#include <string> #include <iostream> #include <cstdio> #include <sstream> #include <algorithm> using namespace std; struct song{ string name; int second; int score; }; int getscore(int you,int my){ if(my>=1&&my<you*1.0/5) return 0; else if(my<you*2.0/5) return 1; else if(my<you*3.0/5) return 2; else if(my<you*4.0/5) return 3; else if(my<you) return 4; else return 5; } bool cmp(song a,song b){ if(a.score==b.score) return a.name<b.name; return a.score>b.score; } int main(){ int n; while(cin>>n){ song songs[101]; if(n==0) break; for(int i=0;i<n;i++){ string name; string time; cin>>name>>time; stringstream ss(time); string temp; int times[2]={0}; int count=0; while(getline(ss,temp,':')){ times[count++]=stoi(temp); } songs[i].name=name; songs[i].second=times[0]*60+times[1]; } int m; cin>>m; for(int i=0;i<m;i++){ string name; string time; cin>>name>>time; stringstream ss(time); string temp; int times[2]={0}; int count=0; while(getline(ss,temp,':')){ times[count++]=stoi(temp); } for(int j=0;j<n;j++){ if(name==songs[j].name){ songs[j].score+=getscore(songs[j].second,times[0]*60+times[1]); } } } sort(songs,songs+n,cmp); for(int i=0;i<n;i++){ cout<<songs[i].name<<" "<<songs[i].score<<endl; } } return 0; } |
Double click to view unformatted code.