zjut1672 TV play I

http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1672

#include<iostream>
#include<iomanip>
#include<string>
#include<map>
using namespace std;
int num(string s)
{
	string ss;
	ss.clear();
	int sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!='.')ss+=s[i];
		
	}
	for(int i=0;i<ss.size();i++)
	{
         sum=sum*10+(ss[i]-'0');
	}
	return sum;
}
int main()
{
	cout.precision(1);
   int n,cas=0;
   string s,ss;
   map<string,int> m;
   map<string,int> c;
   while(scanf("%d",&n)==1)
   {
	   cas++;
	   m.clear();
	   c.clear();
	   for(int i=0;i<n;i++)
	   {
		   ss.clear();
            while(cin>>s)
			{
				if(s.find('.')!=s.npos)
				{
					ss=ss.substr(0,ss.size()-1);
					c[ss]++;
					m[ss]+=num(s);
					break;
					
				}
				ss+=s+' ';
			}	
	   } 
	   map <string,int> ::iterator it1;
	  
	   double ans=0;
	   string ANS;
	   for(it1=m.begin();it1!=m.end();it1++)
	   {
		   if((it1->second)>ans*c[it1->first])
		   {
			   ans=(it1->second)*1.0/c[it1->first];
			   ANS=it1->first;
		   }
	   }
	   cout<<cas<<" "<<ANS<<" "<<fixed<<ans*1.0/10<<endl;	   
   }
}
posted on 2011-05-07 00:10  4.5.6  阅读(204)  评论(0编辑  收藏  举报