View Code of Problem 100

#include<bits/stdc++.h>
using namespace std;
struct node{
	string name;
	int s;
	int sc;
};
int ad(int x,int y){
	int ans;
	if(x==y)ans=5;
	else if(y*5>=x*4)ans=4;
	else if(y*5>=x*3)ans=3;
	else if(y*5>=x*2)ans=2;
	else if(y*5>=x)ans=1;
	else ans=0;
	return ans;
}
bool cmp(struct node x,struct node y){
	if(x.sc==y.sc)
	return x.name<y.name;
	return x.sc>y.sc;
}
int main(){
	int n,mm,ss;
	while(cin>>n&&n!=0){
		struct node mp[n];
		for(int i=0;i<n;++i){
			cin>>mp[i].name;
			scanf("%d:%d",&mm,&ss);
			mp[i].s=mm*60+ss;
			mp[i].sc=0;
		}
		int m;cin>>m;
		string str;
		for(int i=0;i<m;++i){
			int k=0,ks;
			cin>>str;
			scanf("%d:%d",&mm,&ss);
			ks=mm*60+ss;
			for(k;k<n;++k){
				if(str==mp[k].name)
				break;
			}
			mp[k].sc+=ad(mp[k].s,ks);
		}
		sort(mp,mp+n,cmp);
		for(int i=0;i<n;++i){
			cout<<mp[i].name<<" "<<mp[i].sc<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 100