1047 編程團體賽 (20 分)
- 2019 年 11 月 7 日
- 筆記
版權聲明:本文為部落客原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/shiliang97/article/details/100022836
1047 編程團體賽 (20 分)
編程團體賽的規則為:每個參賽隊由若干隊員組成;所有隊員獨立比賽;參賽隊的成績為所有隊員的成績和;成績最高的隊獲勝。
現給定所有隊員的比賽成績,請你編寫程式找出冠軍隊。
輸入格式:
輸入第一行給出一個正整數 N(≤104),即所有參賽隊員總數。隨後 N 行,每行給出一位隊員的成績,格式為:隊伍編號-隊員編號 成績
,其中隊伍編號
為 1 到 1000 的正整數,隊員編號
為 1 到 10 的正整數,成績
為 0 到 100 的整數。
輸出格式:
在一行中輸出冠軍隊的編號和總成績,其間以一個空格分隔。注意:題目保證冠軍隊是唯一的。
輸入樣例:
6 3-10 99 11-5 87 102-1 0 102-3 100 11-9 89 3-2 61
輸出樣例:
11 176
水題,整個數組存大小,maxid 和max存輸出資訊,實時判斷更新
最後輸出就行
#include<iostream> using namespace std; int team[10005]; int main(){ int n,a,b,c,max=0,maxid=0; cin>>n; for(int i=0;i<n;i++){ scanf("%d-%d %d",&a,&c,&b); team[a]+=b; if(team[a]>max){ max=team[a]; maxid=a; } } cout<<maxid<<" "<<max; return 0; }
柳婼是最後比較的。沒有實時更新
#include <iostream> using namespace std; int main() { int n, t, num, score; cin >> n; int team[1001] = {0}; for (int i = 1; i <= n; i++) { scanf("%d-%d %d", &t, &num, &score); team[t] += score; } int max = 0; for (int i = 0; i < 1001; i++) { if (team[max] < team[i]) max = i; } cout << max << " " << team[max]; return 0; }