PTA 乙级 1047 编程团体赛 (20分) C/C++
由于队伍数量有限(上限1000),直接创建队伍的数组,对应队伍成绩累加即可
C/C++
1 #include<iostream> 2 3 using namespace std; 4 5 int main() { 6 int n = 0; 7 /*队伍编号,队员编号,成绩*/ 8 int teamnum = 0, mem = 0, grad = 0; 9 /*初始化队伍成绩*/ 10 int team[1001] = { 0 }; 11 cin >> n; 12 for (int i = 0; i < n; ++i) { 13 scanf("%d-%d %d", &teamnum, &mem, &grad); //VS编辑器需要变为scanf_s 14 team[teamnum] += grad; //对应队伍编号的队伍成绩进行累加 15 } 16 for (int i = 0; i < 1001; ++i) 17 if (team[i] > team[teamnum]) teamnum = i; //求得最大值 18 cout << teamnum << " " << team[teamnum]; 19 return 0; 20 }
Long time no see, 今日是水题,水水水!
默默地一点点变强,细节决定成败