View Code of Problem 100

#include <bits/stdc++.h>
using namespace std;
typedef struct{
	string name;
	int min;
	int s;
	int grade=0;
}music;
bool cmp(music a,music b){
	if(a.grade==b.grade)
		return a.name<b.name;
	return a.grade>b.grade;
}
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		music list[n];
		for(int i=0;i<n;i++){
			cin>>list[i].name;
			scanf("%d:%d",&list[i].min,&list[i].s);
			list[i].s=list[i].min*60+list[i].s;
		}
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			string temp;
			int m,s;
			cin>>temp;
			scanf("%d:%d",&m,&s);
			s=m*60+s;
			for(int j=0;j<n;j++){
				if(temp==list[j].name){
					if(1.0*s < 1.0*list[j].s/5) list[j].grade+=0;
					else if(1.0*s < 1.0*list[j].s/5*2) list[j].grade+=1;
					else if(1.0*s < 1.0*list[j].s/5*3) list[j].grade+=2;
					else if(1.0*s < 1.0*list[j].s/5*4) list[j].grade+=3;
					else if(1.0*s < 1.0*list[j].s) list[j].grade+=4;
					else if(s==list[j].s) list[j].grade+=5;
				}
			}
		}
		sort(list,list+n,cmp);
		for(int i=0;i<n;i++){
			cout<<list[i].name<<" "<<list[i].grade<<endl;
		}
	}

	
} 

Double click to view unformatted code.


Back to problem 100