题目链接:http://codeforces.com/problemset/problem/2/A

A. Winner
time limit per test

1 second

memory limit per test

64 megabytes

input

standard input

output

standard output

The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number
of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name
score", where name is a player's name, and score is
the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m)
at the end of the game, than wins the one of them who scored at least m points first. Initially
each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.

Input

The first line contains an integer number n (1  ≤  n  ≤  1000), n is
the number of rounds played. Then follow n lines, containing the information about the rounds in "name
score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is
an integer number between -1000 and 1000, inclusive.

Output

Print the name of the winner.

Sample test(s)
input
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew

题意:

给出一些列的名字和分数!正的表示加分。负的表示减分!

求终于分数最大的人的名字。

假设分数最大的人有多个。输出最先达到最大分数的人。

代码例如以下:

#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<string, int> a,b;
string s[1017]; int main()
{
int x[1017];
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> s[i] >> x[i];
a[s[i]]+=x[i];
}
int maxx = 0;
for(int i = 1; i <= n; i++)
{
if(a[s[i]] > maxx)
maxx = a[s[i]];
} for(int i = 1; i <= n; i++)
{
b[s[i]]+=x[i];
if((b[s[i]]>=maxx) && (a[s[i]]>=maxx))//在终于分数是最大的人中,选首先达到最大分数的人
{
cout << s[i];
break;
}
}
return 0;
}

CodeForces 2A - Winner(模拟)的更多相关文章

  1. CodeForces 2A Winner

    Winner Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  2. codeforces 2A Winner (好好学习英语)

    Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...

  3. Codeforces 2A :winner

    A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...

  4. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  6. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  7. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. Codeforces 679B. Barnicle 模拟

    B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...

  9. CodeForces 382C【模拟】

    活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...

随机推荐

  1. python3-开发进阶Flask的基础

    一.概述 最大的特点:短小精悍.可拓展强的一个Web框架.注意点:上下文管理机制,依赖wsgi:werkzurg 模块 二.前奏学习werkzurg 先来回顾一个知识点:一个类加括号会执行__init ...

  2. Android消息机制——Handler

      /**android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个MessageQueue(消息队列), * 但是MessageQueue被封装到Looper里 ...

  3. HDU 5645 DZY Loves Balls 水题

    DZY Loves Balls 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5645 Description DZY loves playing b ...

  4. Codeforces Round #300 D. Weird Chess 水题

    D. Weird Chess Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/proble ...

  5. 使用Keras实现机器翻译(英语—>法语)

    import numpy as np from keras.models import Model from keras.models import load_model from keras.lay ...

  6. iOS防止button重复点击

    项目中常会遇到在按钮的点击事件中去执行一些耗时操作.如果处理不当经常会出现连续多次点击push多次的情况,造成不好的用户体验. 一种情况是用户快速连续点击,这种情况无法避免.另一种情况是点击一次后响应 ...

  7. centos安装gcc

    1.安装gcc基本开发工具环境 yum groupinstall 'Development Tools' 2.安装完成后查看安装是否成功 whereis gcc 3.查看gcc版本 gcc --ver ...

  8. iOS 热更新方案 - lance的专栏 - 博客频道 - CSDN.NET

    iOS 热更新方案 - lance的专栏 - 博客频道 - CSDN.NET Weex

  9. Out of memory: Kill process 内存不足

    服务直接被 killed,感觉特别奇怪.代码肯定是没有问题的,但为什么放到服务器上就出错了呢. 部署时报错如下: Failed to add the deployment content to the ...

  10. linux查找超过一定时间的文件,并批量删除

    1.find . -maxdepth 4  -name "*-*" -mtime 3 -maxdepth的值决定是否对下面的子目录进行递归查找 -mtime 3表示查找刚好3天的: ...