結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー satanicsatanic
提出日時 2016-03-31 21:19:39
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,813 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 68,228 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 13:22:39
合計ジャッジ時間 1,704 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <algorithm>

#define SHOW(d) {std::cout << #d << "\t:" << d << "\n";}

template<typename T>
int GetSign(T x){
    if(x==0) return 1;
    return x/std::abs(x);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int n;
    std::string input, inputInt, inputDec;
    long long int ansInt = 0, ansDec = 0;
    std::cin >> n;
    for(int i=0; i<n; ++i){
        std::cin >> input;
        if(input.find('.') == std::string::npos){
            ansInt += static_cast<long long int>(std::stod(input)) + ((input[0]=='-') ? 1 : -1);
            ansDec += ((input[0]=='-') ? -10000000000 : 10000000000);
        }else{
            std::istringstream ist(input);
            std::getline(ist, inputInt, '.');
            ansInt += static_cast<long long int>(std::stod(inputInt)) + ((input[0]=='-') ? 1 : -1);
            std::getline(ist, inputDec);
            while(inputDec.size()<10){
                inputDec += '0';
            }
            ansDec += static_cast<long long int>(std::stod(inputDec)) * ((input[0]=='-') ? -1 : 1) + ((input[0]=='-') ? -10000000000 : 10000000000);
        }
    }
    if(GetSign(ansInt)*GetSign(ansDec)<0){
        int tmp = GetSign(ansDec);
        ansInt += ((ansDec/10000000000==0) ? 0 : ansDec/10000000000);
        ansDec = std::abs(ansDec%10000000000 + 10000000000 * GetSign(ansInt))%10000000000;
        ansInt += (ansDec==0) ? 0 : tmp;
    }else{
        ansInt += ansDec/10000000000;
        ansDec = (ansDec + 10000000000) % 10000000000;
    }
    inputDec = std::to_string(std::abs(ansDec));
    std::cout << ansInt << '.';
    for(unsigned int i=0; i<10-inputDec.size(); ++i){
        std::cout << '0';
    }
    std::cout << inputDec << "\n";

    return 0;
}
0