Team B -1047 PAT program (20 minutes)

Click on the link full solution summary PAT B -AC

Title:
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

Sample output:

11 176

My code:

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int main()
{
    int group[1010]={0};
    int N;
    cin>>N;
    for(int i=0;i<N;i++)
    {
        int a,b,c;
        scanf("%d-%d %d",&a,&b,&c);
        group[a]+=c;
    }
    int id=0;
    for(int i=0;i<1010;i++)
    {
        if(group[i]>group[id])id=i;
    }
    cout<<id<<" "<<group[id];
    return 0;
}

Published 82 original articles · won praise 1 · views 1689

Guess you like

Origin blog.csdn.net/qq_34451909/article/details/104812163