結果
問題 | No.708 (+ー)の式 |
ユーザー |
|
提出日時 | 2022-10-01 05:45:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 677 bytes |
コンパイル時間 | 1,807 ms |
コンパイル使用メモリ | 192,336 KB |
最終ジャッジ日時 | 2025-02-07 20:02:30 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int g()’: main.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type] 21 | } | ^
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; string s; int i = 0; int f(); int g() { if(isdigit(s[i])) { int res = s[i] - '0'; i++; return res; } if(s[i] == '(') { i++; int res = f(); i++; return res; } } int f() { int res = g(); while(true) { if(s[i] == '+') { i++; res += g(); } else if(s[i] == '-') { i++; res -= g(); } else { return res; } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cin >> s; cout << f() << endl; }