POJ 2643-Election(map容器水之)

POJ 2643-Election(map容器水之)

这道题的大意是:
有n个党派,每个党派有一位主席,现在选举国家领导人,m个人投票,看看获胜的是那个党或者是个人;
PS:题目里没说清楚,就是每个党派只有一个候选人,这个要注意下,其它的没什么好说的了,此题不难。
#include < iostream >
#include
< cmath >
#include
< string >
#include
< algorithm >
#include
< map >
using   namespace  std;

map
< string , string > mymap_party;
map
< int , string > mymap_name;
map
< string , int > mymap_index;

int  votenum[ 1000000 ];

int  main()
{
    
int i;
    
int n,m;
    memset(votenum,
0,sizeof(votenum));
    scanf(
"%d",&n);
    cin.ignore();
    
for(i=1;i<=n;i++)
    
{
        
string temp1;
        
string temp2;
        getline(cin,temp1);
        getline(cin,temp2);
        mymap_party[temp1]
=temp2;
        mymap_name[i]
=temp1;
        mymap_index[temp1]
=i;
    }

    scanf(
"%d",&m);
    cin.ignore();
    
for(i=1;i<=m;i++)
    
{

        
string temp;
        getline(cin,temp);
        votenum[mymap_index[temp]]
++;
    }

    
int max=0;
    
int maxmark=0;
    
int secmax=0;
    
for(i=1;i<=n;i++)
    
{

        
if(votenum[i]>max)
        
{
            secmax
=max;
            max
=votenum[i];
            maxmark
=i;
        }

        
else if(votenum[i]>secmax)
        
{
            secmax
=votenum[i];
        }

    }

    
string test("independent");
    
if(max==secmax)
        printf(
"tie\n");
    
else if(max!=secmax&&mymap_party[mymap_name[maxmark]]==test)
        cout
<<mymap_name[maxmark]<<endl;
    
else 
        cout
<<mymap_party[mymap_name[maxmark]]<<endl;
    system(
"pause");


    
return 0;

}









你可能感兴趣的:(POJ 2643-Election(map容器水之))