結果

問題 No.222 引き算と足し算
ユーザー rogi52rogi52
提出日時 2020-11-19 22:50:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,374 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 166,812 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 18:11:49
合計ジャッジ時間 4,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    string s; cin >> s;
    bool xisminus = false, yisminus = false, op = true;
    xisminus = (s[0] == '-');
    rep(i,s.size()-1){
        if(s[i] == '-' && s[i+1] == '-'){
            yisminus = true;
            op = false;
        }else if(s[i] == '+' && s[i+1] == '-'){
            yisminus = true;
            op = true;
        }
    }
    rep(i,s.size()-2){
        if(s[i+1] == '-'){
            if(s[i+2] != '+' && s[i+2] != '-'){
                if(s[i] != '+' && s[i] != '-'){
                    op = false;
                }
            }
        }
    }

    string x = "";
    if(xisminus){
        rep(i,s.size()){
            if(i == 0) continue;
            if(s[i] == '+' || s[i] == '-') break;
            x += s[i];
        }
    }else{
        rep(i,s.size()){
            if(s[i] == '+' || s[i] == '-') break;
            x += s[i];
        }
    }

    string y = "";
    for(int i=x.size() + (xisminus); i<s.size();i++){
        if(s[i] == '+' || s[i] == '-') continue;
        y += s[i];
    }

    int X = stoi(x), Y = stoi(y);
    if(xisminus) X = - X;
    if(yisminus) Y = - Y;
    if(op){
        cout << X - Y << endl;
    }else{
        cout << X + Y << endl;
    }
}
0