PAT Basic 1032
生活随笔
收集整理的這篇文章主要介紹了
PAT Basic 1032
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1032?挖掘機技術哪家強?(20 分)
注意紅色標記,想當然地認為了循環范圍,實際可以取值到n
數組范圍也應當定義到a[100001]
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#define max 100001
#define debug 0
using namespace std;
int main() {
#if debug
?? ?freopen("in.txt", "r", stdin);
#endif
?? ?int a[max] = {0}, n = 0, temp = 0, score;
?? ?cin >> n;
?? ?for (int i = 0; i < n; i++)
?? ?{
?? ??? ?cin >> temp>>score;
?? ??? ?a[temp] += score;
?? ?}
?? ?int ma = 0;
?? ?for (int i = 1; i <=n; i++)
?? ?{
?? ??? ?if (a[ma] < a[i])
?? ??? ?{
?? ??? ??? ?ma = i;
?? ??? ?}
?? ?}
?? ?cout << ma << ' ' << a[ma];
#if debug
?? ?freopen("CON", "r", stdin);
#endif
?? ?return 0;
}
為了用事實說明挖掘機技術到底哪家強,PAT 組織了一場挖掘機技能大賽。現請你根據比賽結果統計出技術最強的那個學校。
輸入格式:
輸入在第 1 行給出不超過?10?5???的正整數?N,即參賽人數。隨后?N?行,每行給出一位參賽者的信息和成績,包括其所代表的學校的編號(從 1 開始連續編號)、及其比賽成績(百分制),中間以空格分隔。
輸出格式:
在一行中給出總得分最高的學校的編號、及其總分,中間以空格分隔。題目保證答案唯一,沒有并列。
輸入樣例:
6 3 65 2 80 1 100 2 70 3 40 3 0輸出樣例:
2 150注意紅色標記,想當然地認為了循環范圍,實際可以取值到n
數組范圍也應當定義到a[100001]
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#define max 100001
#define debug 0
using namespace std;
int main() {
#if debug
?? ?freopen("in.txt", "r", stdin);
#endif
?? ?int a[max] = {0}, n = 0, temp = 0, score;
?? ?cin >> n;
?? ?for (int i = 0; i < n; i++)
?? ?{
?? ??? ?cin >> temp>>score;
?? ??? ?a[temp] += score;
?? ?}
?? ?int ma = 0;
?? ?for (int i = 1; i <=n; i++)
?? ?{
?? ??? ?if (a[ma] < a[i])
?? ??? ?{
?? ??? ??? ?ma = i;
?? ??? ?}
?? ?}
?? ?cout << ma << ' ' << a[ma];
#if debug
?? ?freopen("CON", "r", stdin);
#endif
?? ?return 0;
}
轉載于:https://www.cnblogs.com/lxzbky/p/10507431.html
總結
以上是生活随笔為你收集整理的PAT Basic 1032的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [CTSC2017]吉夫特
- 下一篇: Codeforces 868F Yet