結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-09-29 04:24:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,121 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 98,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:43:53
合計ジャッジ時間 2,247 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0