結果

問題 No.708 (+ー)の式
ユーザー donkorin_donkorin_
提出日時 2018-07-09 11:18:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 144,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 08:34:39
合計ジャッジ時間 1,938 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll sub()’:
main.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int i = 0;
ll solve();
ll sub() {
    if ('0' <= s[i] && s[i] <= '9') {
        ll val = s[i] - '0';
        i++;
        return val;
    }
    if (s[i] == '(') {
        i++;
        ll val = solve();
        i++;
        return val;
    }
}

ll solve() {
    ll clc = sub();
    while (true) {
        if (s[i] == '+') {
            i++;
            clc += sub();
        } else if (s[i] == '-') {
            i++;
            clc -= sub();
        } else 
            return clc;
    }
}

int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    cout << solve() << endl;
    return 0;
}
0