結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー aaaaaaiu
提出日時 2019-08-23 18:40:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 773 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 195,504 KB
最終ジャッジ日時 2025-01-07 14:43:08
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin>>n;
    ll a=0,b=0;
    while (n--) {
        string s;cin>>s;
        int sign=1;
        if (s[0]=='-') {
            sign=-1;
            s=s.substr(1);
        }
        int i;
        for (i=0;i<s.size();i++)
            if (s[i]=='.')
                break;
        if (i==s.size())
            s+='.';
        while (s.size()-1-i<10)
            s+='0';
        ll c,d;
        sscanf(s.c_str(),"%lld.%lld",&c,&d);
        a+=c*sign;
        b+=d*sign;
    }
    while (b>=1e10) b-=1e10,a++;
    while (b<0) b+=1e10,a--;
    if (a<0&&b>0) {
        a++;
        b=10000000000LL-b;
        if (a==0) cout<<'-';
    }
    printf("%lld.%010lld\n",a,b);
    return 0;
}
0