結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー face4face4
提出日時 2018-08-24 17:04:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 80,828 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 21:35:06
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;

typedef long long ll;
const ll INF = 1e10;

vector<string> split(string str, char del){
    vector<string> ret;
    string cutoff = "";
    for(int i = 0; i < str.length(); i++){
        if(str[i] == del){
            if(cutoff != "")    ret.push_back(cutoff);
            cutoff = "";
        }else{
            cutoff += str[i];
        }
    }
    if(cutoff != "")    ret.push_back(cutoff);
    return ret;
}

int main(){
    int n;
    cin >> n;

    ll integer = 0, decimal = 0;
    for(int i = 0; i < n; i++){
        string line;
        cin >> line;
        if(count(line.begin(), line.end(), '.')){
            vector<string> v = split(line, '.');
            integer += stoll(v[0]);
            while(v[1].size() != 10)    v[1] += "0";
            decimal += stoll(v[1]) * (v[0][0] == '-' ? -1 : 1);
        }else{
            integer += stoll(line);
        }
    }

    if(abs(decimal) >= INF){
        integer += decimal/INF;
        decimal %= INF;
    }

    bool minus = false;
    if(decimal < 0){
        if(integer != 0){
            integer--;
            decimal += INF;
        }else{
            minus = true;
            decimal = abs(decimal);
        }
    }

    if(minus)   cout << "-";
    cout << integer << "." << right << setw(10) << setfill('0') << decimal << endl;

    return 0;
}
0