【題解】ZeroJudge a130: 12015 – Google is Feeling Lucky

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=a130

  • 依序讀入10個頁面,及其相關度,同時紀錄相關度的最大值 (mx_score)。
  • 列印出所有相關度為 mx_score 的頁面。
#include <iostream>
using namespace std;
 
int main() {
    int T;
    string page[10];
    int V[10];
    cin >> T;
    for (int Case = 1; Case <= T; Case++){
        int mx_score = 0;
        for (int i = 0; i < 10; i++){
            cin >> page[i] >> V[i];
            mx_score = max(mx_score, V[i]);
        }
        cout << "Case #" << Case << ":\n";
        for (int i = 0; i < 10; i++) {
            if (V[i] == mx_score) {
                cout << page[i] << "\n";
            }
        }
    }
    return 0;
}

Python code (credit: Amy Chou)

T = int(input())

for TC in range(1, T+1):
    page = []
    score = []
    for i in range(10):
        s, v = input().split()
        page.append(s)
        score.append(int(v))
    
    mx = 100
    found = 0
    print(f"Case #{TC}:")
    while mx > 0 and found == 0:
        for i in range(10):
            if score[i] == mx:
                print(page[i])
                found += 1
        mx -= 1
分享本文 Share with friends