結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-25 01:53:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 907 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 61,552 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 16:29:28 |
| 合計ジャッジ時間 | 1,316 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#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));
}
ans1 += num1;
ans2 += (s[0] == '-') ? -num2 : num2;
if (ans2 < 0) {
ans1--;
ans2 += MOVEUP;
} else if (ans2 >= MOVEUP) {
ans1++;
ans2 -= MOVEUP;
}
}
if (ans1 >= 0 || ans2 == 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;
}