PAT basic 1047 Team program (20 minutes) C ++

One, Title Description

Rules for Programming Team: Each team composed of several members; all members of the independent game; teams score of all the players and the results; the highest team score wins.

Now given all the players race results, you write a program to find the winning team.

Input format:
given a positive input of the first line integer N (≦ 10 . 4 ), i.e., the total number of all team members. Then N rows, each player is given a score, in the format: Team number - number team scores, the ranks of which number is a positive integer of 1 to 1,000, players number is a positive integer from 1 to 10, 0 to 100 scores integer.

Output formats:
Output championship team number and total score in a row, during which separated by a space. Note: The title winning team is the only guarantee.

Sample input:
. 6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61 is

Sample output:
11176

Second, the code

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<map>
#include<stdlib.h>
using namespace std;
//1047

int main()
{
	int n;
	cin >> n;
	string temp;
	int tempscore;
	map<int, int>a;
	for (int i = 0; i < n; i++)
	{
		cin >> temp>>tempscore;
		a[stoi(temp)] += tempscore;
	}
	int max = 0;
	int maxpos;
	for (auto it: a)
	{
		if (it.second > max)
		{
			maxpos = it.first;
			max = it.second;
		}
	}
	cout << maxpos << " " << max;


	system("pause");
	return 0;
}

Third, the operating results

Here Insert Picture Description

Collection title

Here Yo ~

Published 42 original articles · won praise 0 · Views 697

Guess you like

Origin blog.csdn.net/qq_44352065/article/details/104100732