結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-22 10:15:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,210 bytes |
| コンパイル時間 | 816 ms |
| コンパイル使用メモリ | 81,220 KB |
| 最終ジャッジ日時 | 2025-01-09 22:25:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
using lint = long long;
constexpr lint D = 10000000000;
void solve() {
int n;
std::cin >> n;
lint x = 0, f = 0;
while (n--) {
std::string s;
std::cin >> s;
if (!std::count(s.begin(), s.end(), '.')) s += ".0";
bool neg = (s.front() == '-');
if (neg) s.erase(s.begin());
lint nx = 0;
while (s.front() != '.') {
nx = nx * 10 + s.front() - '0';
s.erase(s.begin());
}
s.erase(s.begin());
while (s.length() < 10) s.push_back('0');
lint nf = std::stoll(s);
x += nx * (neg ? -1 : 1);
f += nf * (neg ? -1 : 1);
}
while (f < 0) {
f += D;
--x;
}
while (f >= D) {
f -= D;
++x;
}
bool neg = (x < 0);
if (neg && f > 0) {
++x;
f = D - f;
}
std::cout << (x == 0 && neg ? "-" : "") << x << "."
<< std::setw(10) << std::setfill('0') << f
<< std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}