#include<iostream> using namespace std; int cmp(string a, string b) { int i=0; while(i<a.length()&&i<b.length()) { //都转小写 if(a[i]>='A'&&a[i]<='Z') a[i]=char(a[i]+32); if(b[i]>='A'&&b[i]<='Z') b[i]=char(b[i]+32); if(a[i]==b[i]) i++; else if(a[i]<b[i]) { return 1; }else { return 2; } } return 0; } int main() { int m,n,mm,ss; while(cin>>n) { if(n==0) break; string a[n]; int time[n],score[n]; for(int i=0; i<n; i++) { cin>>a[i]; scanf("%d:%d",&mm,&ss); time[i]=mm*60+ss; score[i]=0; } cin>>m; string b[m]; int time2[m]; for(int i=0; i<m; i++) { cin>>b[i]; scanf("%d:%d",&mm,&ss); time2[i]=mm*60+ss; } //统计得分 for(int j=0; j<m; j++) { for(int i=0; i<n; i++) { if(b[j]==a[i]) { if(time2[j]>=time[i]*0.2&&time2[j]<time[i]*0.4) { score[i]+=1; }else if(time2[j]>=time[i]*0.4&&time2[j]<time[i]*0.6) { score[i]+=2; }else if(time2[j]>=time[i]*0.6&&time2[j]<time[i]*0.8) { score[i]+=3; }else if(time2[j]>=time[i]*0.8&&time2[j]<time[i]) { score[i]+=4; }else if(time2[j]==time[i]) { score[i]+=5; }else { } } } } //稳定排序 int j,temp; string temp2; for(int i=1; i<n; i++) { temp=score[i]; temp2=a[i]; if(temp>=score[i-1]) { for(j=i-1; j>=0; j--) { if(temp>score[j]) { score[j+1]=score[j]; a[j+1]=a[j]; }else if(temp==score[j]) { if(cmp(temp2,a[j])==1) {//temp2更小 score[j+1]=score[j]; a[j+1]=a[j]; }else { break; } }else { break; } } if(j+1!=i) { score[j+1]=temp; a[j+1]=temp2; } } } //输出 for(int i=0; i<n; i++) { cout<<a[i]<<" "<<score[i]<<endl; } } } |
Double click to view unformatted code.