# UVa 11136 - Hoax or what ## Online Judge  ## 解題思路 看得懂題目就有思路了。 ## 解題中出現的bug Wrong Answer 的部分 1. Answer用int會overflow 2. 再刪除set裡的數字時,要注意容器裡是否為空 p.s.尤其是第25行 ## Code ```cpp= #include <iostream> #include <set> using namespace std; int main() { int Cases; int n, m; while(cin >> Cases && Cases!=0) { multiset<int> bills; long long int case_answer = 0; while(Cases--) { cin >> n; for(int i=0;i<n;i++) { cin >> m; bills.insert(m); } if(!bills.empty()) { case_answer += *(--bills.end()) - *bills.begin(); bills.erase(bills.begin()); if(!bills.empty()) bills.erase(--bills.end()); } } cout << case_answer << endl; } return 0; } ``` ###### tags: `UVA code` `cpp` `林基成-C++` `Awwwolf的刷題之路`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up