这题其实就是一个简单的排序,但某渣太差了,代码写了很长,字典序排序也是一个一个字符去比较
看了别人代码才发现其实用strcmp 就可以了
自己代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<limits.h>
using namespace std;
struct node
{
int m;
int s;
char ch[111];
}list[15];
int cmp(node x,node y)
{
if(x.m < y.m)
return 1;
else if(x.m > y.m)
return 0;
else if(x.m==y.m)
{
if(x.s < y.s)
return 1;
else if(x.s > y.s)
return 0;
else if(x.s==y.s)
{
int l1= strlen(x.ch);
int l2= strlen(y.ch);
int min= l1 < l2? l1: l2;
for(int i= 0; i< min; i++)
{
if(x.ch[i]< y.ch[i])
return 1;
else if(x.ch[i]> y.ch[i])
return 0;
}
if(l1 < l2)
return 1;
else
return 0;
}
}
}
int main()
{
int n;
int T= 0;
while(scanf("%d",&n)!=EOF&&n)
{
T++;
for(int i= 1; i<= n; i++)
scanf("%s %d:%d",&list[i].ch,&list[i].m,&list[i].s);
sort(list+1,list+n+1,cmp);
if(T!=1)
printf("\n");
printf("Case #%d\n",T);
printf("%s 1\n",list[1].ch);
int flag= 1;
for(int i= 2; i<= n; i++)
{
if(list[i].m==list[i-1].m&&list[i].s==list[i-1].s)
printf("%s %d\n",list[i].ch,flag);
else
{
printf("%s %d\n",list[i].ch,i);
flag= i;
}
}
}
return 0;
}
别人写的cmp:
int cmp(p a,p b)
{
if(a.m!=b.m)
return a.m<b.m;
else if(a.s!=b.s)
return a.s<b.s;
else
return strcmp(a.name,b.name)<0;
}