CF2A:Help!
  • 板块CF2A Winner
  • 楼主Merron
  • 当前回复1
  • 已保存回复1
  • 发布时间2020/8/27 11:36
  • 上次更新2023/11/6 19:11:53
查看原帖
CF2A:Help!
338370
Merron楼主2020/8/27 11:36

RT

求助,为啥第一个点就错了。 求大佬指点。

#include <bits/stdc++.h>
using namespace std ;

struct User
{
	string name ;
	int score ;
} ;

int head ;
string a[1050] ;
int b[1050] ;


User u[1050] ;
int n ;

int find(string k)
{
	for (int i = 1 ;i <= head ;i ++)
	{
		if (u[i].name == k)
		{
			return i ;
		}
	}
	return -1 ;
}

bool cmp(User a, User b)
{
	return a.score > b.score ;
}

int s ;

int main()
{
	cin >> n ;
	for (int i = 1 ;i <= n ;i ++)
	{
		cin >> a[i] ;
		cin >> b[i] ;
		int res = find(a[i]) ;
		if (res == -1)
		{
			head ++ ;
			u[head].name = a[i] ;
			u[head].score += b[i] ;
		}
		else
		{
			u[res].score += b[i] ;
		}
	}
	sort(u + 1, u + n + 1, cmp) ;
	s = u[1].score ;
	for (int i = 1 ;i <= head ;i ++)
	{
		u[i].score = 0 ;
	}
	for (int i = 1 ;i <= n; i ++)
	{
		u[find(a[i])].score += b[i] ;
		for (int j = 1 ;j <= head ;j ++)
		{
			if (u[j].score >= s)
			{
				cout << u[j].name << endl ;
				return 0 ;
			}
		}
	}
	return 0 ;
}
2020/8/27 11:36
加载中...