結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
le_panda_noir
|
| 提出日時 | 2020-06-13 18:06:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,462 bytes |
| コンパイル時間 | 1,028 ms |
| コンパイル使用メモリ | 76,424 KB |
| 最終ジャッジ日時 | 2025-01-11 03:51:14 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
#include <iostream>
#include <iomanip>
using namespace std;
using ll = long long;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
int main() {
int N; cin >> N;
ll integer = 0, decimal = 0;
rep(i, N) {
string s; cin >> s;
bool negative = s[0] == '-';
if (negative) s = s.substr(1);
auto pos = s.find(".");
if (s == "0") continue;
if (pos == string::npos)
integer += (negative ? -1 : 1) * stoll(s);
else {
integer += (negative ? -1 : 1) * stoll(s.substr(0, pos));
int len = s.size() - 1 - pos;
rep(j, 10-len)
s += "0";
s = s.substr(pos+1);
while (!s.empty() && s[0] == '0') s = s.substr(1);
if (!s.empty())
decimal += (negative ? -1 : 1) * stoll(s);
}
}
integer += decimal / 10000000000LL;
decimal %= 10000000000LL;
if (integer > 0 && decimal >= 0 || integer < 0 && decimal <= 0) {
cout << integer << "." << setfill('0') << setw(10) << abs(decimal) << endl;
} else {
if (integer == 0) {
cout << (decimal < 0 ? "-0." : "0.") << setfill('0') << setw(10) << abs(decimal)<<endl;
return 0;
}
if (integer < 0) {
integer *= -1;
decimal *= -1;
cout << "-";
}
if (decimal != 0 && integer != 0) --integer;
cout << integer <<"." << setfill('0') << setw(10) << 10000000000LL-abs(decimal)<<endl;
}
return 0;
}
le_panda_noir