A. Winner

本文介绍了一种用于确定Berlogging卡牌游戏胜者的算法,Berlogging是在Berland流行的卡牌游戏。文章详细解释了游戏规则,即在游戏结束时,如果只有一个玩家拥有最高分数,则该玩家获胜;如果有两个或更多玩家拥有相同最高分数,则首先达到该分数的玩家获胜。通过分析玩家每轮获得的分数,使用C++代码实现了这一逻辑。

链接:https://codeforces.com/contest/2/problem/A

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.

Examples

input

Copy

3
mike 3
andrew 5
mike 2

output

Copy

andrew

input

Copy

3
andrew 3
andrew 2
mike 5

output

Copy

andrew

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,t,k,max1=0;
long long a[100001];
string s[100001];
map<string ,long long >m,q;
main()
{
	cin>>n;
	for(int i = 1; i <=n; i++)
	{
		cin >> s[i] >> a[i];
		m[s[i]] += a[i];
	}
	for(int i = 1; i <=n; i++)
	{
		max1 = max(m[s[i]], max1);
	}
	string ans;
	for(int i =1;i<=n;i++)
	{
		q[s[i]]+=a[i];
		if(q[s[i]]>=max1&&m[s[i]]==max1)
		{
			ans = s[i];
			break;
		}
	}
	cout<<ans;
	
} 

 

这个问题的根本原因是 SQL 语句中对表别名 **`g`** 的重复使用,导致数据库无法确定某个字段到底属于哪个表。 ### 原因分析: 在你的 SQL 中: ```sql LEFT JOIN wms_base_department g ON g.department_id = a.department_id ... LEFT JOIN wms_work_order_info g ON g.work_order_id = a.work_order_id ``` 你两次使用了相同的别名 `g` 来代表不同的表: - 第一次是 `wms_base_department` 表,别名为 `g` - 第二次是 `wms_work_order_info` 表,也用了别名 `g` 这就会导致 SQL 报错: ``` java.sql.SQLSyntaxErrorException: Not unique table/alias: 'g' ``` 即:别名 `g` 不唯一,SQL 引擎无法分辨后续查询中使用的 `g` 到底指的是哪一个表。 --- ### 解决方案: 你需要为这两个表分配不同的别名。例如: ```sql SELECT count(0) FROM ( SELECT a.work_order_id, a.company_id, a.work_order_num, a.`status`, a.project_id, a.pass_code, total_code, b.project_code, b.project_name, a.is_scene, a.create_time, c.real_name, d.real_name AS operator_name, a.reason, a.order_type, a.type, a.use_type, h.making_time, a.remark, a.bid_winner, a.source_id, a.bid_num, a.department, a.return_person, a.recept_person, a.inspect_person, a.handle_person, a.apply_name, e.work_order_num AS sourceWorkOrderNum, a.staff_names, a.return_type, a.erp, a.print_num, a.team_ids, a.operator_time, a.department_id, a.handover_time, a.application_batch, g1.department_name, g2.some_column -- 如果你需要来自 wms_work_order_info 的字段,请明确列出 FROM wms_work_order a LEFT JOIN wms_base_project b ON a.project_id = b.project_id LEFT JOIN wms_sys_admin c ON c.admin_id = a.creator_id LEFT JOIN wms_sys_admin d ON d.admin_id = a.operator_id LEFT JOIN wms_work_order_detail e ON a.work_order_id = e.work_order_id LEFT JOIN wms_base_supplier f ON f.supplier_id = e.supplier_id LEFT JOIN wms_work_order_message h ON a.work_order_id = h.work_order_id LEFT JOIN wms_base_department g1 ON g1.department_id = a.department_id LEFT JOIN wms_work_order_info g2 ON g2.work_order_id = a.work_order_id WHERE a.status >= 0 AND type = ? AND order_type = ? AND a.company_id = ? GROUP BY a.work_order_id ) table_count ``` #### 修改点总结: - 将第一个 `g` 改为 `g1`(对应 `wms_base_department`) - 将第二个 `g` 改为 `g2`(对应 `wms_work_order_info`) 这样就解决了别名冲突的问题。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值