The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

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;

}









posted on 2009-04-04 17:12 abilitytao 阅读(376) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理