結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-23 20:55:50 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,461 bytes |
| コンパイル時間 | 546 ms |
| コンパイル使用メモリ | 65,784 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 06:22:45 |
| 合計ジャッジ時間 | 1,330 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 6 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
const long long convert = 1e10;
int main() {
int n;
string s;
long long ans1 = 0; // 整数部
long long ans2 = 0; // 小数部
long long tmp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
int pos = s.find('.', 0);
ans1 += atoll(s.substr(0, pos).c_str());
if (pos != string::npos) {
tmp = atof(s.substr(pos).c_str()) * convert;
// ans2 += (long long) (s[0] == '-' ? -tmp : tmp);
// (s[0] == '-') ? ans2 += tmp : ans2 -= tmp;
if (s[0] == '-') {
ans2 -= (long long)tmp;
} else {
ans2 += (long long)tmp;
}
}
// printf("%23s %13lld %13lld %13lld\n",
// s.c_str(),
// atoll(s.substr(0, pos).c_str()),
// pos == string::npos ? 0 : tmp,
// ans2
// );
}
// printf("a %lld %lld\n", ans1, ans2);
// cout << 1.0 * ans2 / convert << endl;
// 0 <= ans2 < 1e10 にする
if (ans2 < 0) {
ans1 += floor(1.0 * ans2 / convert);
ans2 -= floor(1.0 * ans2 / convert) * convert;
} else {
ans1 += ans2 / convert;
ans2 -= ans2 / convert * convert;
}
// printf("b %lld %lld\n", ans1, ans2);
// ans1 ans2の符号を同じにする
if (ans1 < 0 && ans2 > 0) {
ans1++;
ans2 -= convert;
}
// printf("c %lld %lld\n", ans1, ans2);
if (ans1 == 0 && ans2 < 0) {
printf("-");
}
printf("%lld.%010lld\n", ans1, abs(ans2));
return 0;
}