Page 2 of 3

Posted: Mon Aug 07, 2006 8:24 am
by Darko
I am not sure what your point is there, Leonid.

Are you saying that if someone tells you that you should compare strings lexicographically, you shouldn't compare them character by character, using those characters' ASCII values?

I am not saying that it is wrong to compare strings in some other way, I am just saying that it is unusual (look at Java - it has String.compareTo(String) and String.compareToIgnoreCase(String), why is that?). If you want a different kind of comparison, it should be specified, that's all.

Posted: Mon Aug 07, 2006 11:30 am
by Leonid
Darko wrote:If you want a different kind of comparison, it should be specified, that's all.
As I've mentioned before I do agree with that. My point was: "The truth is out there" :) And I think we've discussed this topic and won't find any new "truth".

Posted: Tue Aug 08, 2006 12:39 am
by leocm
Why WA? The output is perfect with the input we have here...

Code: Select all

Accepted!

Posted: Tue Aug 08, 2006 4:24 am
by Martin Macko
leocm wrote:Why WA? The output is perfect with the input we have here...
Try this input:

Code: Select all

13
a : 12 min 17 sec 673 ms
b : 25 min 40 sec 56 ms
c : 17 min 54 sec 902 ms
d : 44 min 9 sec 625 ms
e : 15 min 44 sec 136 ms
f : 24 min 53 sec 376 ms
g : 8 min 53 sec 355 ms
h : 24 min 20 sec 527 ms
i : 57 min 14 sec 171 ms
j : 23 min 48 sec 93 ms
k : 57 min 14 sec 59 ms
l : 38 min 13 sec 277 ms
m : 36 min 44 sec 288 ms

Correct output is:

Code: Select all

Row 1
g
a
Row 2
e
c
Row 3
j
h
Row 4
f
b
Row 5
m
l
Row 6
d
k
Row 7
i


Posted: Tue Aug 08, 2006 8:26 pm
by leocm
Thank you Martin!! Now AC! The mistake was only one wrong comparison...

case insensitive

Posted: Thu Aug 10, 2006 7:57 am
by f.eliel
how do i make the comparison case insensitive?
i'm using strcmp now, and i saw strcasecmp in some guy's code, but it didn't work. Can you help me?

Re: case insensitive

Posted: Thu Aug 10, 2006 8:29 am
by Martin Macko
f.eliel wrote:how do i make the comparison case insensitive?
i'm using strcmp now, and i saw strcasecmp in some guy's code, but it didn't work. Can you help me?
strcasecmp() should work well enoung here. Alternatively, you can make lowercase copies of the strings a compare them.

Posted: Sun Aug 20, 2006 1:34 pm
by w k
Another question to case insensitive comparison. What is the correct output for:

2
a1 : 1 min 1 sec 1 ms
aa : 1 min 1 sec 1 ms

Is it:

Row1
a1
aa

?

Wojciech

Posted: Sun Aug 20, 2006 4:24 pm
by helloneo
w k wrote: Is it:

Row1
a1
aa

?
Yes, it is..

Posted: Mon Aug 28, 2006 11:22 am
by IRA
Does have this input data?

3
Schumacher : 3 min 23 sec 172 ms
Barrichello : 2 min 12 sec 999 ms
Schumacher : 1 min 23 sec 172 ms


is the output as follow?

Row 1
Schumacher
Barrichello

Posted: Mon Aug 28, 2006 11:30 am
by StatujaLeha
IRA wrote:Does have this input data?

3
Schumacher : 3 min 23 sec 172 ms
Barrichello : 2 min 12 sec 999 ms
Schumacher : 1 min 23 sec 172 ms


is the output as follow?

Row 1
Schumacher
Barrichello
Your output is wrong. Read carefully problem statement again http://acm.uva.es/p/v110/11056.html .
If there are two pilots with the same name on a test case, they are different pilots and the output must contain both pilots.

Posted: Mon Aug 28, 2006 12:43 pm
by IRA
Thank you!
I got AC!

Posted: Mon Aug 28, 2006 1:00 pm
by StatujaLeha
IRA wrote:Thank you!
I got AC!
:)

Posted: Sat Oct 28, 2006 8:41 pm
by albet_januar
get WA.. anybody can help me??

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
	char name[100];
	int minute;
	int second;
	int msecond;
	long long time;
} racer;

int sorting_function(const void *a, const void *b)
{
	racer *x = (racer *) a;
	racer *y = (racer *) b;

	if(x->minute != y->minute)
		return x->minute - y->minute;
	else if(x->second != y->second)
		return x->second - y->second;
	else if(x->msecond != y->msecond)
		return x->msecond - y->msecond;
	else if(x->msecond != y->msecond)
		return x->time - y->time;
	else
		return (strcmp((char *) x->name, (char *) y->name));
}

int main()
{
	int n;
	racer pembalap[101];
	char menit[100], sec[100], ms[100];
	char coba;
	int i;
	int race;
	int count;

	while(scanf("%d",&n)!=EOF)
	{
		race = 1;
		count = 0;

		for(i=0;i<n;i++)
		{
			scanf("%s %c %2d %s %2d %s %3d %s", pembalap[i].name, &coba, &pembalap[i].minute, menit, &pembalap[i].second, sec, &pembalap[i].msecond, ms);
			pembalap[i].time = (pembalap[i].minute * 60000) + (pembalap[i].second * 1000) + pembalap[i].msecond;
		}

		qsort(pembalap, n, sizeof(racer), sorting_function);

		for(i=0;i<n;i++)
		{
			if(count%2==0) printf("Row %d\n", race++);
			printf("%s\n", pembalap[i].name);
			++count;
		}

		printf("\n");

	}

	return 0;

}

Posted: Tue Oct 31, 2006 8:14 am
by nymo
to albet_januar, your sort function is wrong, and one more thing... you have to compare names in case insensitive order. strcmp() is case sensitive