結果
問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
ユーザー |
|
提出日時 | 2015-05-25 01:40:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 955 bytes |
コンパイル時間 | 438 ms |
コンパイル使用メモリ | 62,060 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 08:09:37 |
合計ジャッジ時間 | 1,342 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 WA * 3 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> using namespace std; const long long MOVEUP = 1e10; int main() { int n; string s; long long num1, num2; long long ans1 = 0, ans2 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s; int pos = s.find('.'); if (pos == string::npos) { num1 = stoll(s); num2 = 0; } else { num1 = stoll(s.substr(0, pos)); num2 = stoll(s.append(10, '0').substr(pos + 1, 10)); } // printf("%30s %10lld.%10lld\n", s.c_str(), num1, num2); ans1 += num1; ans2 += (s[0] == '-') ? -num2 : num2; if (ans2 < 0) { ans1--; ans2 += MOVEUP; } else if (ans2 >= MOVEUP) { ans1++; ans2 -= MOVEUP; } } if (ans1 >= 0) { printf("%lld.%010lld\n", ans1, ans2); } else if (ans1 == -1) { printf("-0.%010lld\n", abs(ans2 - MOVEUP)); } else { printf("%lld.%010lld\n", ans1 + 1, abs(ans2 - MOVEUP)); } return 0; }