結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー BantakoBantako
提出日時 2018-12-28 19:42:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 2,242 ms
コンパイル使用メモリ 166,848 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:14:45
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
ll MOD = 1e9;
int charsearch(string s,char c){
    //文字cが文字列sに含まれるかどうか
    rep(i, 0, s.length()){
        if(s[i] == c)return i;
    }
    return -1;
}
main(){
    int sign = 1;
    ll num[2] = {};
    int N;
    cin >> N;
    rep(i,0,N){
        string s;
        cin >> s;
        cout << s << endl;
        int ind = charsearch(s,'.');
        ll a,b;
        if(ind != -1){
            //cout << s.substr(0,ind) << endl;
            //cout << s.substr(ind+1) << endl;
            a = stoll(s.substr(0,ind));
            b = stoll(s.substr(ind+1) + string(9 - (s.size() - ind - 1), '0') );
            //cout << a << " " << b << endl;  
        }else{
            a = stoll(s);
            b = 0;
        }
        int sign2 = s[0] == '-' ? -1 : 1;
        a = abs(a);
        if(sign == sign2){
            num[1] += b;
            num[0] += a + (num[1] / MOD);
            num[1] %= MOD;
        }else{
            if(num[0] < a || num[0] == a && num[1] < b){
                swap(num[0], a);
                swap(num[1], b);
                sign = sign2;
            }
            num[1] -= b;
            if(num[1] < 0){
                num[0]--;
                num[1] += MOD;
            }
            num[0] -= a;
        }
    }
    num[0] *= sign;
    printf("%lld.%010lld", num[0], num[1]);
}
0