結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-13 20:32:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,953 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 149,668 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 22:43:28
合計ジャッジ時間 3,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N;
string over("0000000000"), under("0000000000");
int dot = 0;
bool flag = false;

int main(void){
    
    cin >> N;
    
    int i;
    
    for(i = 0; i < N; ++i){
        string s;
        cin >> s;
        
        if(s.find(".") == string::npos){ //小数点以下なし
            
            over = to_string(stoll(s) + stoll(over));
            
        }
        else{   //小数点以下あり
            string aaaa, bbbb;
            aaaa = s.substr(0, s.find("."));
            bbbb = s.substr(s.find(".") + 1);
            
            over = to_string(stoll(aaaa) + stoll(over));
            
            while(bbbb.size() != 10) bbbb += '0';
            under = to_string( ((s[0] == '-') ? stoll(bbbb) * (-1) : stoll(bbbb)) + ((flag) ? stoll(under) * (-1) : stoll(under)) );
            
            if(under[0] == '-'){
                flag = true;
                under.erase(under.begin());
            }
            else flag = false;
            if(under.size() >= 10) dot = under.size() - 10;
            while(under.size() < 10) under = '0' + under;
            
        }
    }
    
    if(dot != 0){ //繰り上がりあり
        string plus;
        plus = under.substr(0, dot);
        under = under.substr(dot);
        over = to_string(stoll(over) + ((flag) ? stoll(plus) * (-1) : stoll(plus)) );
    }
    
    if(stoll(over) != 0 && stoll(under) != 0 && ((over[0] == '-' && !flag) || (over[0] != '-' && flag))){ //整数部分と小数部分の符号が不一致 
        over = (stoll(over) > 0) ? to_string(stoll(over) - 1) : to_string(stoll(over) + 1);
        under = to_string(10000000000 - stoll(under));
        flag = (flag) ? false : true;
        while(under.size() < 10) under = '0' + under;
    }
    
    if(over[0] == '0' && flag) cout << "-" << over << "." << under << endl;
    else cout << over << "." << under << endl;
    
    return 0;
    
}
0