結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-02 01:28:12
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,352 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 77,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 13:02:05
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string stringplus(string a,string b) {
    string ret;
    if(a.size() < b.size()) swap(a,b);

    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());

    int carry = 0;
    rep(i,b.size()) {
        int x = a[i] - '0';
        int y = b[i] - '0';
        int z = x + y + carry;

        carry = z / 10;
        ret.push_back('0' + (z%10));
    }

    REP(i,b.size(),a.size()) {
        int x = a[i] - '0';
        int z = x + carry;

        carry = z / 10;
        ret.push_back('0' + (z%10));
    }

    if(carry) ret.push_back('0' + carry);
    reverse(ret.begin(),ret.end());
    return ret;
}

vector<string> split(const string &str, char delim) {
    vector<string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != string::npos) {
        res.push_back(string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(string(str, current, str.size() - current));
    return res;
}

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

    ll a = 0, b = 0;
    rep(i,n) {
        string s;
        cin >> s;

        vector<string> ret = split(s,'.');
        ll t;
        stringstream ss;
        ss << ret[0];
        ss >> t;

        a += t;

        if(ret.size() == 2) {
            int size = ret[1].size();
            rep(i,10-size) {
                ret[1] += "0";
            }

            ll t2;
            stringstream ss2;
            ss2 << ret[1];
            ss2 >> t2;

            if(ret[0][0] == '-') {
                b -= t2;
            } else {
                b += t2;
            }
        }
    }

    a += b/10000000000;
    b %= 10000000000;

    if(a < 0 && b > 0) {
        a++;
        b -= 10000000000;
    }

    if(a > 0 && b < 0) {
        a--;
        b += 10000000000;
    }

    b = abs(b);

    cout << a << ".";
    stringstream res;
    res << b;
    string ans = res.str();
    int size = ans.size();
    rep(i,10-size) ans = "0" + ans;
    cout << ans << endl;

    return 0;
}
0