結果

問題 No.708 (+ー)の式
ユーザー rogi52rogi52
提出日時 2022-10-01 05:42:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 752 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 197,580 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-24 22:59:56
合計ジャッジ時間 2,809 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int g(std::string&, int)’ 内:
main.cpp:19:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   19 | }
      | ^

ソースコード

diff #

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

int g(string&, int);
int f(string&, int);
int g(string &s, int i) {
    if(isdigit(s[i])) {
        int res = s[i] - '0';
        i++;
        return res;
    }
    if(s[i] == '(') {
        i++;
        int res = f(s, i);
        i++;
        return res;
    }
}

int f(string &s, int i) {
    int res = g(s, i);
    while(true) {
        if(s[i] == '+') {
            i++;
            res += g(s, i);
        } else if(s[i] == '-') {
            i++;
            res -= g(s, i);
        } else break;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s; cin >> s;
    int i = 0;
    cout << f(s, i) << endl;
}
0