HDU2115——排序

http://acm.hdu.edu.cn/showproblem.php?pid=2115

 

W又是在Output a blank line between two cases

 

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Student { char names[100]; char time[6]; }; Student s[15]; int N; bool cmp(Student s1,Student s2) { int i,j; if(strcmp(s1.time,s2.time)<0) { return true; } else if(strcmp(s1.time,s2.time)==0) { //notice in lexicographic order for(i=0,j=0;i<(int)strlen(s1.names)&&j<(int)strlen(s2.names);i++,j++) { if(s1.names[i]<s2.names[j]) return true; else if(s1.names[i]>s2.names[j]) return false; else continue; } } else return false; } int main() { int i,count,counti=1; while(scanf("%d",&N)&&N!=0) { for(i=0;i<N;i++) { scanf("%s %s",s[i].names,s[i].time); } sort(s,s+N,cmp); if(counti!=1) //notice Output a blank line between two cases. printf("/n"); printf("Case #%d/n",counti); count = 1; for(i=0;i<N;i++) { if(i==0) { printf("%s %d/n",s[i].names,count); } else { if(strcmp(s[i].time,s[i-1].time)!=0) { count=i+1; } printf("%s %d/n",s[i].names,count); } } counti++; } return 0; }

你可能感兴趣的:(ini,output)