• POJ 2643 Election


    Election
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3558   Accepted: 1692

    Description

    Canada has a multi-party system of government. Each candidate is generally associated with a party, and the party whose candidates win the most ridings generally forms the government. Some candidates run as independents, meaning they are not associated with any party. Your job is to count the votes for a particular riding and to determine the party with which the winning candidate is associated.

    Input

    The first line of input contains a positive integer n satisfying 2 <= n <= 20, the number of candidates in the riding. n pairs of lines follow: the first line in each pair is the name of the candidate, up to 80 characters; the second line is the name of the party, up to 80 characters, or the word "independent" if the candidate has no party. No candidate name is repeated and no party name is repeated in the input. No lines contain leading or trailing blanks. 
    The next line contains a positive integer m <= 10000, and is followed by m lines each indicating the name of a candidate for which a ballot is cast. Any names not in the list of candidates should be ignored. 

    Output

    Output consists of a single line containing one of: 
    • The name of the party with whom the winning candidate is associated, if there is a winning candidate and that candidate is associated with a party. 
    • The word "independent" if there is a winning candidate and that candidate is not associated with a party. 
    • The word "tie" if there is no winner; that is, if no candidate receives more votes than every other candidate.

    Sample Input

    3
    Marilyn Manson
    Rhinoceros
    Jane Doe
    Family Coalition
    John Smith
    independent
    6
    John Smith
    Marilyn Manson
    Marilyn Manson
    Jane Doe
    John Smith
    Marilyn Manson
    

    Sample Output

    Rhinoceros
    #include<iostream>  
    #include<stdio.h>  
    #include<string.h>  
    #include<string>  
    #include<algorithm>  
    #include<math.h>  
    #include<iomanip>  
    #include<queue>  
    #include<map>  
    using namespace std;
    
    int main()
    {
        int Max = -1;
        bool flag = false;
        map<string, string> ss;
        map<string, int> st;
        char Name[85], Party[85];
        int n;
        cin>>n;
        getchar();
        for (int i = 0; i < n; i++)
        {
            gets(Name);
            gets(Party);
            ss[Name] = Party;
        }
        cin>>n;
        getchar();
        string result;
        for (int i = 0; i< n; i++)
        {
            gets(Name);
            if (ss[Name] == "")
            {
                continue;
            }
            int nCount = ++st[Name];
            if (nCount > Max)
            {
                flag = true;
                result = Name;
                Max = nCount;
            }
            else
            {
                if (nCount == Max)
                {
                    flag = false;
                }
            }
        }
        if (flag)
        {
            cout<<ss[result]<<endl;
        }
        else
        {
            cout<<"tie"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    WPF获取程序版本号(Version)的方法
    WPF中Popup等弹窗的位置不对(偏左或者偏右)
    WPF中Expander与ListBox(ItemsControl)嵌套中的问题
    WPF自定义Button样式(按钮长度随Content长度自适应)
    WPF解决当ScrollViewer中嵌套ItemsControl时,不能使用鼠标来滚动翻页
    WPF中Window的ShowInTaskbar、Owner和Topmost属性
    WPF通过<x:Array>直接为ListBox的ItemsSource赋值
    常用的谓词和逻辑运算符
    利用OVER开窗函数分页
    一个单表查询的示例
  • 原文地址:https://www.cnblogs.com/lzmfywz/p/3178736.html
Copyright © 2020-2023  润新知