11056 - Formula 1
Moderator: Board moderators
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.
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.
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.
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Try this input:leocm wrote:Why WA? The output is perfect with the input we have here...
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
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
case insensitive
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?
i'm using strcmp now, and i saw strcasecmp in some guy's code, but it didn't work. Can you help me?
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: case insensitive
strcasecmp() should work well enoung here. Alternatively, you can make lowercase copies of the strings a compare them.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?
-
- Learning poster
- Posts: 91
- Joined: Tue May 31, 2005 2:01 pm
- Location: Russia
Your output is wrong. Read carefully problem statement again http://acm.uva.es/p/v110/11056.html .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
If there are two pilots with the same name on a test case, they are different pilots and the output must contain both pilots.
-
- Learning poster
- Posts: 91
- Joined: Tue May 31, 2005 2:01 pm
- Location: Russia
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
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;
}