結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー face4
提出日時 2018-08-24 16:56:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 14:26:48
合計ジャッジ時間 2,553 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 20
権限があれば一括ダウンロードができます

ソースコード

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

    cout << integer << "." << left << setw(10) << setfill('0') << decimal << endl;

    return 0;
}
0