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[];
};
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 = ; i < n; i++) {
for (mapIterator = myMap1.begin(); mapIterator != myMap1.end();
mapIterator++) {
if ( == strcmp(node[i].name, mapIterator->first.c_str())) {
// printf("%d %d %s\n", 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\n", 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 = ; i < n; i++) {
scanf("%s%d", node[i].name, &node[i].val);
node[i].index = i;
myMap[node[i].name] +=node[i].val;
}
nmax = -;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax < mapIterator->second){
nmax = mapIterator->second;
}
}
m = ;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax == mapIterator->second){
nmaxStr = mapIterator->first;
myMap1[mapIterator->first] = ;
m ++;
}
}
//printf("%d %d\n",m,nmax);
if(m != ){
find(n,nmax);
}else{
printf("%s\n",nmaxStr.c_str());
}
}
return ;
}
codeforces Winner的更多相关文章
- codeforces 2A Winner (好好学习英语)
Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...
- CodeForces 2A - Winner(模拟)
题目链接:http://codeforces.com/problemset/problem/2/A A. Winner time limit per test 1 second memory limi ...
- CodeForces 2A Winner
Winner Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Codeforces Beta Round #2 A. Winner 水题
A. Winner 题目连接: http://www.codeforces.com/contest/2/problem/A Description The winner of the card gam ...
- Codeforces 2A :winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- Codeforces Beta Round #2 A. Winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- Codeforces Gym100952 A.Who is the winner? (2015 HIAST Collegiate Programming Contest)
A. Who is the winner? time limit per test 1 second memory limit per test 64 megabytes input stan ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! 二分
C. Everyone is a Winner! On the well-known testing system MathForces, a draw of n rating units is ar ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)
链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...
随机推荐
- OAuth2集成——《跟我学Shiro》
http://jinnianshilongnian.iteye.com/blog/2038646 目前很多开放平台如新浪微博开放平台都在使用提供开放API接口供开发者使用,随之带来了第三方应用要到开放 ...
- Android 6.0doze和standby 的一点理解
之前写的压力测试程序,在开发版和5.0上面测试好好的,即使熄灭屏幕也会跑.我的程序主要是在Activity里面开启了一个thread,其中不断在界面上显示任务信息.换到6.0的 机器上面,发现一个现象 ...
- android事件分发介绍
Android事件分发 事件分发3个步骤 dispatchTouchEvent(event)派发 onInterceptTouchEvent(event)拦截 onTouchEvent(eve ...
- 敌情篇 ——DDoS攻击原理
敌情篇 ——DDoS攻击原理 DDoS攻击基础 DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是 ...
- jquery之each
$.each()与$(selector).each()不同, 后者专用于jquery对象的遍历, 前者可用于遍历任何的集合(无论是数组或对象),如果是数组,回调函数每次传入数组的索引和对应的值(值亦可 ...
- nodejs连接MySQL数据库
在github上搜索orm2 https://github.com/dresende/node-orm2: 在项目文件夹使用npm install orm下载下来,然后书写配置文件 var orm = ...
- java培训(5-8节课)
面向对象: 1.利用面向对象的语法,实现代码的拆分(数据存储:对象的传值). 2.利用面向对象的语法,实现程序的结构处理(继承,多态,接口,抽象类). 3.用面向对象的编程方法,理解实现程序开发的框架 ...
- mysql学习笔记5
phpmyadmin中向数据表中插入新数据 INSERT INTO tb_admin(`table_id`, `table_name`, `table_des`, `table_time`) VAL ...
- JSTL之迭代标签库
JSTL之迭代标签库 JSTL的全称是 Java Server Pages Standard Tag Library,翻译过来就是JSP标准标签库,它包含了在开发JSP页面时经常用到的一组标准标签.这 ...
- Node安装与环境配置
1.nodejs(npm)安装 下载nodejs(http://nodejs.cn/)安装后,cmd下如输入 node -v 与 npm -v 出现下图版本提示就是完成了NodeJS的安装 2.n ...