結果

問題 No.708 (+ー)の式
ユーザー rogi52
提出日時 2022-10-01 05:42:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 752 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 192,312 KB
最終ジャッジ日時 2025-02-07 20:02:23
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int g(std::string&, int)’:
main.cpp:19:1: warning: control reaches end of non-void function [-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