11056 - Formula 1

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Mon Aug 07, 2006 8:24 am

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.

Leonid
Experienced poster
Posts: 146
Joined: Thu Dec 22, 2005 5:50 pm
Contact:

Post by Leonid » Mon Aug 07, 2006 11:30 am

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".

leocm
New poster
Posts: 22
Joined: Fri Jul 21, 2006 9:44 am
Location: Brasil

Post by leocm » Tue Aug 08, 2006 12:39 am

Why WA? The output is perfect with the input we have here...

Code: Select all

Accepted!
Last edited by leocm on Tue Aug 08, 2006 8:26 pm, edited 1 time in total.

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Tue Aug 08, 2006 4:24 am

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


leocm
New poster
Posts: 22
Joined: Fri Jul 21, 2006 9:44 am
Location: Brasil

Post by leocm » Tue Aug 08, 2006 8:26 pm

Thank you Martin!! Now AC! The mistake was only one wrong comparison...

f.eliel
New poster
Posts: 10
Joined: Wed Feb 08, 2006 4:31 pm

case insensitive

Post by f.eliel » Thu Aug 10, 2006 7:57 am

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?

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: case insensitive

Post by Martin Macko » Thu Aug 10, 2006 8:29 am

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.

w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post by w k » Sun Aug 20, 2006 1:34 pm

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

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Sun Aug 20, 2006 4:24 pm

w k wrote: Is it:

Row1
a1
aa

?
Yes, it is..

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA » Mon Aug 28, 2006 11:22 am

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

StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

Post by StatujaLeha » Mon Aug 28, 2006 11:30 am

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.

IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA » Mon Aug 28, 2006 12:43 pm

Thank you!
I got AC!

StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

Post by StatujaLeha » Mon Aug 28, 2006 1:00 pm

IRA wrote:Thank you!
I got AC!
:)

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar » Sat Oct 28, 2006 8:41 pm

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;

}

nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

Post by nymo » Tue Oct 31, 2006 8:14 am

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
regards,
nymo

Post Reply

Return to “Volume 110 (11000-11099)”