Submission details
Task:Kayaks
Sender:Olli-Pekka Lindström
Submission time:2015-09-09 17:24:32 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.05 sdetails
#40.06 sdetails
#50.05 sdetails
#60.07 sdetails
#70.05 sdetails
#80.06 sdetails
#90.05 sdetails
#100.05 sdetails
#110.05 sdetails
#120.06 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &h, &w);
                        ^
input/code.cpp:42:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", tmp);
                   ^

Code

#include <cstdio>
#include <cstring>

int findint(char* s){
	while(*s != 0x00){
		if(*s <= '9' && *s > '0')
			return *s-'0';
		s++;
	}
	return -1;
}
int get_dist(char* s){
	int i=0;
	while(*s != 0x00){
		if(*s <= '9' && *s > '0')
			return i;
		s++;
		i++;
	}
	return -1;
}

int get_max(int* dists){
	int i;
	int max = 0;
	for(i=0; i<9; i++){
		if(dists[i] > max) max = dists[i];
	}
	return max;
}

int main(){
	int w,h;
	scanf("%d %d", &h, &w);
	char raw[h][w+1];
	int i;
	int boat;
	int boats = 0;
	char tmp[w+10];
	memset(tmp, 0, w+10);
	for (i=0; i<h; i++){
		scanf("%s", tmp);
		boat = findint(tmp);
		if (boat == -1) continue;
		boats++;
		strcpy(raw[boat], tmp);
	}
	//boats are in numeric order
	//for (i=0; i<h; i++) printf("%s\n", raw[i]);	

	int dists[h];
	memset(dists, 0, h);
	for (i=1; i <= boats; i++){
		dists[i] = get_dist(raw[i]);
		//printf("%d\n", dists[i]);
	}
	//we have distances from the start for each boat
	
	int row;
	int rank = 1;
	int max;
	int rankings[boats];
	memset(rankings, 0, boats);
	for(row=0; row<boats; row++){
		max = get_max(dists);
		for (boat=1; boat<=boats; boat++){
			if (dists[boat] == max){
				rankings[boat] = rank;
				dists[boat] = -1;
			}
		}
		rank++;
	}
	for (i=1; i<h; i++) printf("%d\n", rankings[i]);	
	return 0;
}

Test details

Test 1

Verdict:

input
10 15
S..........222F
S.....111.....F
S...333.......F
S...555.......F
...

correct output
5
1
6
3
6
...

user output
4
1
5
2
5
...

Test 2

Verdict: ACCEPTED

input
10 10
S.....111F
S....222.F
S...333..F
S..444...F
...

correct output
1
2
3
4
5
...

user output
1
2
3
4
5
...

Test 3

Verdict: ACCEPTED

input
10 10
S...111..F
S....222.F
S.....333F
S444.....F
...

correct output
3
2
1
6
5
...

user output
3
2
1
6
5
...

Test 4

Verdict:

input
10 20
S..................F
S...111............F
S......222.........F
S.........333......F
...

correct output
9
7
5
3
1
...

user output
8
6
4
2
1
...

Test 5

Verdict:

input
20 20
S999...............F
S..................F
S..................F
S..................F
...

correct output
5
3
7
6
4
...

user output
5
3
7
6
4
...

Test 6

Verdict:

input
30 30
S............................F...

correct output
1
6
5
4
3
...

user output
1
5
4
3
2
...

Test 7

Verdict:

input
30 30
S111.........................F...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...

Test 8

Verdict:

input
30 30
S111.........................F...

correct output
7
6
5
3
2
...

user output
7
6
5
3
2
...

Test 9

Verdict:

input
30 30
S............................F...

correct output
1
1
1
1
3
...

user output
1
1
1
1
3
...

Test 10

Verdict:

input
30 30
S............................F...

correct output
5
3
3
3
1
...

user output
5
3
3
3
1
...

Test 11

Verdict:

input
30 30
S............................F...

correct output
6
5
3
5
4
...

user output
5
4
2
4
3
...

Test 12

Verdict:

input
30 30
S............................F...

correct output
5
4
3
1
2
...

user output
5
4
3
1
2
...