CodeForces 2A - Winner(模拟)
题目链接:http://codeforces.com/problemset/problem/2/A
1 second
64 megabytes
standard input
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.
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.
Print the name of the winner.
3
mike 3
andrew 5
mike 2
andrew
3
andrew 3
andrew 2
mike 5
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(模拟)的更多相关文章
- CodeForces 2A Winner
Winner Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- codeforces 2A Winner (好好学习英语)
Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...
- Codeforces 2A :winner
A. Winner time limit per test 1 second memory limit per test 64 megabytes input standard input outpu ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces 679B. Barnicle 模拟
B. Barnicle time limit per test: 1 second memory limit per test :256 megabytes input: standard input ...
- CodeForces 382C【模拟】
活生生打成了大模拟... #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsig ...
随机推荐
- px,dp,sp以及像素密度
px px(pixel): 像素,是指在由一个数字序列表示的图像中的一个最小单位.在Android中,无论屏幕密度多少,一个像素单位对应一个屏幕像素单位,不会根据屏幕密度自动缩放,因此一般不推荐使用p ...
- JSONObject 和 JSONArray 的区别和用法
JSONObject 和 JSONArray 的数据表现形式不同: JSONObject的数据是用 { } 来表示的,例如: { "id" : "1", &q ...
- GIT 提交步骤
1.提交 git add .
- [转]web服务器apache架构与原理 &apache 监控
web服务器 在开始了解Apache前,我 ...
- React-如何在jsx中自动补全标签(vscode)
痛点: React库最近的增长趋势很明显, 很多朋友都在选择学习, 很多公司也在选择使用React栈. 但在使用React库写代码的时候, 有一个很让人苦恼的问题, 就是标签在jsx语法中不能自动补 ...
- 微信、小程序开发UI库--weui
一.weui可以开发微信内网页.微信小程序,二者使用的UI库不一样 1. 微信内网页样式文件为 .css文件 链接地址:https://weui.io/ weui-js库: weu ...
- js继承——到继承结束
说到继承,其它语言里可能有两种: 接口继承是继承方法签名,而实现继承则继承实际方法.ES函数没有签名,不能实现接口继承,只支持实现继承,而实现继承主要依靠原型链.(这两句话,说来轻松,理解来不易,且行 ...
- jdk1.8 foreach
lambda 表达式效率非常低,测试代码可以看到大概3~5倍的差距 遍历Map的方式有很多,通常场景下我们需要的是遍历Map中的Key和Value,那么推荐使用的: public static voi ...
- glob函数的使用
glob库函数用于Linux文件系统中路径名称的模式匹配,即查找文件系统中指定模式的路径.注意,这不是正则表达式匹配,虽然有些相似,但还是有点差别. glob函数原型 #include & ...
- Arcgis10.2中复制后粘贴图标是灰色的,无法粘贴,编辑也打开了,如何解决?
在进程中选择SogouCloud,然后结束进程 关闭sogoucloud.exe进程试试,修改搜狗输入法设置\高级\云计算候选功能,