zoukankan      html  css  js  c++  java
  • codeforces Winner

    /*
     * Winner.cpp
     *
     *  Created on: 2013-10-13
     *      Author: wangzhu
     */
    
    /**
     * 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和中看有几个是和最大的分数和相等,
     * 1)、若有多个,则比较谁在比赛结束钱分数先达到最大分数和,则是赢家;
     * 2)、若只有一个,则直接输出。
     */
    #include<cstdio>
    #include<iostream>
    #include<map>
    #include<string.h>
    using namespace std;
    #define NMAX 1010
    struct Node {
        int index, val;
        char name[33];
    };
    Node node[NMAX];
    map<string, int> myMap;
    map<string, int> myMap1;
    map<string, int>::iterator mapIterator;
    
    void find(int n, int nmax) {
        int m;
        for (int i = 0; i < n; i++) {
            for (mapIterator = myMap1.begin(); mapIterator != myMap1.end();
                    mapIterator++) {
                if (0 == strcmp(node[i].name, mapIterator->first.c_str())) {
                    //    printf("%d %d %s
    ", node[i].index, node[i].val, node[i].name);
                    m = myMap1[mapIterator->first];
                    m += node[i].val;
                    myMap1[mapIterator->first] = m;
                    if (m >= nmax) {
                        printf("%s
    ", node[i].name);
                        return;
                    }
                }
            }
        }
    }
    
    int main() {
        freopen("data.in", "r", stdin);
        int n, m,nmax;
        string nmaxStr;
        while (~scanf("%d", &n)) {
            myMap.clear();
            myMap1.clear();
    
            for (int i = 0; i < n; i++) {
                scanf("%s%d", node[i].name, &node[i].val);
                node[i].index = i;
                myMap[node[i].name] +=node[i].val;
            }
            nmax = -1;
            for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
                if(nmax < mapIterator->second){
                    nmax = mapIterator->second;
                }
            }
            m = 0;
            for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
                if(nmax == mapIterator->second){
                    nmaxStr = mapIterator->first;
                    myMap1[mapIterator->first] = 0;
                    m ++;
                }
            }
            //printf("%d %d
    ",m,nmax);
            if(m != 1){
                 find(n,nmax);
            }else{
                printf("%s
    ",nmaxStr.c_str());
            }
        }
        return 0;
    }
  • 相关阅读:
    C# 图解教程 第一章 C#和.NET框架
    How I explained OOD to my wife(转)
    ListView 无 DataSource 依然用 DataPager 翻页
    【树莓派】crontab的两个问题
    【CentOS 7】scp示例
    【CentOS 7】nginx配置web服务器
    【CentOS_7】安装nginx
    【python 2.7】获取外部参数
    【python 2.7】输入任意字母数字,输出其对应的莫尔斯码并播放声音
    【python 2.7】python读取json数据存入MySQL
  • 原文地址:https://www.cnblogs.com/xiaoxian1369/p/3367004.html
Copyright © 2011-2022 走看看