Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

疯掉……一个小时,那里有错啊?郁闷!

Posted by code_snail at 2010-07-22 17:36:58 on Problem 2643
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
   map<string,string>party;
   map<string,int>vote;
   string str1,str2;
   int m;
   int n;
   cin>>n;
   
      //getline(cin,str1);
      getchar();
   for(int i=0;i<n;i++)
   {
     getline(cin,str1);
     getline(cin,str2);
   

     party[str1]=str2;
     vote[str1]=2;
   }
  
   cin>>m;    
   getchar();
   // getline(cin,str1);       
   for(int i=0;i<m;i++)
   {
   getline(cin,str1);
   if(vote[str1]>=2)
     vote[str1]++;
   }
   int max=0;
   int MK=0;
   map<string,int>::iterator it;
   for(it=vote.begin();it!=vote.end();it++)
   {
     if(it->second>max){
                        str2=it->first;
                        if(MK==1)MK=0;
                        }
     if(it->second==max)MK=1;
   }
   if(MK==1)cout<<"tie"<<endl;
   else cout<<party[str2]<<endl;
  //system("pause");
   return 0;
}
     

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator