結果
問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
ユーザー |
![]() |
提出日時 | 2018-09-29 04:24:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 2,121 bytes |
コンパイル時間 | 1,093 ms |
コンパイル使用メモリ | 101,508 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 16:42:43 |
合計ジャッジ時間 | 1,717 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <math.h> #include <cmath> #include <limits.h> #include <map> #include <unordered_map> #include <set> #include <queue> #include <algorithm> #include <functional> #include <stdio.h> using namespace std; long long MOD = 1000000007; vector<string> split(const string &str, char sep) { vector<string> v; // 分割結果を格納するベクター auto first = str.begin(); // テキストの最初を指すイテレータ while( first != str.end() ) { // テキストが残っている間ループ auto last = first; // 分割文字列末尾へのイテレータ while( last != str.end() && *last != sep ) // 末尾 or セパレータ文字まで進める ++last; v.push_back(string(first, last)); // 分割文字を出力 if( last != str.end() ) ++last; first = last; // 次の処理のためにイテレータを設定 } return v; } int main() { int N; cin >> N; vector<string> VS(N); for ( int i = 0; i < N; i++ ) { cin >> VS[i]; } long long a,b; a = b = 0; for ( int i = 0; i < N; i++ ) { vector<string> s = split(VS[i],'.'); a += stoll( s[0] ); if ( s.size() > 1 ) { string t = s[1]; while ( t.length() < 10 ) { t += '0'; } long long c = ( s[0][0] == '-' ) ? -stoll(t) : stoll(t); b += c; } } a += b/10000000000; b %= 10000000000; // cout << a << endl; // cout << b << endl; if ( a == 0 && b < 0 ) { cout << "-"; } else if ( a > 0 && b < 0 ) { a--; b += 10000000000; } else if ( a < 0 && b > 0 ) { a++; b = 10000000000-b; if ( a == 0 ) { cout << "-"; } } if ( b < 0 ) { b = -b; } string x = to_string(b); string y = ""; for ( int i = 0; i < 10-x.length(); i++ ) { y += '0'; } cout << a << "." << y << x << endl; return 0; }