【PAT B 1047】编程团体赛

#include 
#include 
using namespace std;
const int maxn = 1005;

int list2number(char list[]){
    int num_list[10] = {0},len,count = 1,number = 0,len_list = 0;
    len = strlen(list);
    for(int i = 0;i < len;i++){
        if(list[i] == '-')
            break;
        num_list[len_list++] = list[i] - '0';
    }

    for(int i = len_list - 1;i >= 0;i--){
        number += num_list[i] * count;
        count *= 10;
    }

    return number;
}

int main(){
    int number,num,HashTable[maxn] = {0},score = 0,max = -1,n;
    char list[10];
    cin >> number;
    for(int i = 0;i < number;i++){
        cin >> list;
        num = list2number(list);
        cin >> score;
        HashTable[num] += score;
    }
    for(int i = 0;i < maxn;i++){
        if(HashTable[i] > max) {
            max = HashTable[i];
            n = i;
        }
    }
    cout << n << ' ' << max;

    return 0;
}

你可能感兴趣的:(【PAT B 1047】编程团体赛)