結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー peroonperoon
提出日時 2019-05-03 11:05:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,215 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 173,416 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 05:43:46
合計ジャッジ時間 6,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

vector<string> split_str(string s, char c){
    vector<string> ret;
    stringstream ss;
    FOR(i, 0, s.size()){
        if(s[i]==c){
            ret.push_back(ss.str());
            ss.str("");
            ss.clear();
        }else{
            ss << s[i];
        }
    }
    ret.push_back(ss.str());
    return ret;
}

// n桁にする
string fill_str(string s, ll n){
    ll L = s.size();
    stringstream ss;
    ss << s;
    FOR(i, 0, n-L){
        ss << '0';
    }
    return ss.str();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    cin >> N;

    ll up = 0;
    ll down = 0;
    FOR(i, 0, N){
        string A;
        cin >> A;
        bool is_minus = false;
        if(A[0]=='-'){
            is_minus = true;
            A = A.substr(1);
        }

        auto S = split_str(A, '.');
        if(!is_minus){
            up += stoll(S[0]);
            down += stoll(fill_str(S[1], 10));           
        }else{
            up -= stoll(S[0]);
            down -= stoll(fill_str(S[1], 10));
        }
    }

    // pn(up);
    // pn(down);

    
    // 小数部の切り上げ
    ll kuriagari = down / 1e10;
    up += kuriagari;
    down -= kuriagari * 1e10;

    if(down<0 && up>0){
        up--;
        down += 1e10;
    }

    bool is_minus = false;
    if(up<0 || down<0){
        is_minus = true;
    }
 
    // pn(up);
    // pn(down);
    
    if(is_minus){
        cout << '-';
    }
    cout << abs(up) << '.' << fill_str(to_string(abs(down)), 10) << endl;

    return 0;
}
0