結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
commy
|
| 提出日時 | 2019-03-30 00:38:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,713 bytes |
| コンパイル時間 | 802 ms |
| コンパイル使用メモリ | 77,440 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-22 16:46:31 |
| 合計ジャッジ時間 | 1,691 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <iomanip>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template<typename T>
vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
ll a = 0, b = 0;
REP(i, 0, n) {
string s;
cin >> s;
int sign = 1;
if (s[0] == '-') {
s = s.substr(1);
sign = -1;
}
auto it = s.find('.');
if (it != string::npos) {
REP(j, s.size() - it, 11) {
s += "0";
}
} else {
s += ".0000000000";
}
it = s.find('.');
a += sign * atoll(s.substr(0, it).c_str());
b += sign * atoll(s.substr(it + 1).c_str());
if (a < 0 && b > 0) {
a++;
b = b - 10000000000;
} else if (a > 0 && b < 0) {
a--;
b = 10000000000 + b;
}
if (b >= 10000000000) {
b -= 10000000000;
a++;
}
if (b <= -10000000000) {
b += 10000000000;
a--;
}
}
if (b < 0) {
b *= -1;
if (a == 0) {
cout << '-';
}
}
cout << a << "." << setw(10) << setfill('0') << b << endl;
return 0;
}
commy