結果
問題 | No.81 すべて足すだけの簡単なお仕事です。 |
ユーザー |
|
提出日時 | 2015-01-17 16:55:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,931 bytes |
コンパイル時間 | 1,153 ms |
コンパイル使用メモリ | 94,588 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 16:27:58 |
合計ジャッジ時間 | 2,034 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; pair<long long, long long> add(long long a1, long long b1, long long a2, long long b2) { a1 += a2; b1 += b2; if(b1 >= 10000000000LL){ ++ a1; b1 -= 10000000000LL; } return make_pair(a1, b1); } pair<long long, long long> sub(long long a1, long long b1, long long a2, long long b2) { a1 -= a2; b1 -= b2; if(b1 < 0){ -- a1; b1 += 10000000000LL; } return make_pair(a1, b1); } int main() { int n; cin >> n; bool sign = true; long long a = 0; long long b = 0; for(int i=0; i<n; ++i){ string s; cin >> s; int k = s.find('.'); bool sign2 = s[0] != '-'; long long a2, b2; if(k == string::npos){ if(sign2) a2 = stoll(s); else a2 = stoll(s.substr(1)); b2 = 0; } else{ string x = s.substr(0, k); string y = s.substr(k+1); y.resize(10, '0'); if(sign2) a2 = stoll(x); else a2 = stoll(x.substr(1)); b2 = stoll(y); } if(sign == sign2){ tie(a, b) = add(a, b, a2, b2); } else if(make_pair(a, b) < make_pair(a2, b2)){ sign = sign2; tie(a, b) = sub(a2, b2, a, b); } else{ tie(a, b) = sub(a, b, a2, b2); } } if(!sign) cout << '-'; cout << a << '.' << setfill('0') << setw(10) << b << endl; return 0; }