# APCS實作題2019年6月第1題:籃球比賽 > 日期:2023年9月9日 > 作者:王一哲 > 題目來源:108年6月實作題第1題 > [ZeroJudge 題目連結](https://zerojudge.tw/ShowProblem?problemid=e286) <br /> ## 題目 ### 問題描述 APCS國辦了一場籃球聯賽,其中的每一場有主隊與客隊。你的任務是將每一場比賽的資訊做成簡訊輸出。 <br /> ### 輸入格式 單筆輸入 共有四行數字,代表兩場比賽 每行有四個數字,代表四局的分數 第一行代表主隊在第一場比賽中四局的分數 第二行代表客隊在第一場比賽中四局的分數 第三行代表主隊在第二場比賽中四局的分數 第四行代表客隊在第二場比賽中四局的分數 所有數字都介於 0 ~ 100 之間 <br /> ### 輸出格式 對每一場比賽輸出主隊與客隊的比數 最後輸出兩場比賽的勝敗情況 如果主隊贏了兩場輸出 "Win" 如果客隊贏了兩場輸出 "Lose" 平手則輸出 "Tie" 保證不會有同分狀況出現,每場都會分出勝負 <br /> ### 範例:輸入 ``` 87 87 87 87 78 78 78 78 87 87 87 87 78 78 78 78 ``` ### 範例:正確輸出 ``` 348:312 348:312 Win ``` <br /> ## Python 程式碼 於 ZeroJudge 測試結果,最長運算時間約為 18 ms,使用記憶體最多約為 3.3 MB,通過測試。 ```python= scores = [] # 儲存單場總分用的串列 for i in range(4): # 讀取資料 data = list(map(int, input().split())) # 用空格分隔資料,存入串列 data scores.append(sum(data)) # 計算單場總分,存入串列 scores # 計算主、客隊勝場數 win1, win2 = 0, 0 if scores[0] > scores[1]: win1 += 1 else: win2 += 1 if scores[2] > scores[3]: win1 += 1 else: win2 += 1 # 印出兩場比賽分數 print("{:d}:{:d}".format(scores[0], scores[1])) print("{:d}:{:d}".format(scores[2], scores[3])) # 印出比賽結果 if win1 > win2: print("Win") elif win1 < win2: print("Lose") else: print("Tie") ``` <br /><br /> ## C++ 程式碼 於 ZeroJudge 測試結果,最長運算時間約為 3 ms,使用記憶體最多約為 316 kB,通過測試。 ```cpp= #include <iostream> using namespace std; int main() { int scores[4] = {0}; // 儲存單場總分用的陣列 for(int i=0; i<4; i++) { // 讀取資料 int score = 0, tmp = 0; // 用空格分隔資料,計算單場總分 score for(int j=0; j<4; j++) { cin >> tmp; score += tmp; } scores[i] = score; // 儲存單場總分 } /* 計算主、客隊勝場數 */ int win1 = 0, win2 = 0; if (scores[0] > scores[1]) win1++; else win2++; if (scores[2] > scores[3]) win1++; else win2++; /* 印出兩場比賽分數 */ cout << scores[0] << ":" << scores[1] << endl; cout << scores[2] << ":" << scores[3] << endl; /* 印出比賽結果 */ if (win1 > win2) { cout << "Win" << endl; } else if (win1 < win2) { cout << "Lose" << endl; } else { cout << "Tie" << endl; } return 0; } ``` <br /><br /> --- ###### tags:`APCS`、`Python`、`C++`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.