結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-20 01:57:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 698 bytes |
| コンパイル時間 | 498 ms |
| コンパイル使用メモリ | 63,768 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 08:19:29 |
| 合計ジャッジ時間 | 1,127 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function 'll g()':
main.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
24 | }
| ^
ソースコード
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
string S;
int i = 0;
ll f();
//---------------------------------------------------------------------------------------------------
ll g() {
if ('0' <= S[i] and S[i] <= '9') {
ll res = S[i] - '0';
i++;
return res;
}
if (S[i] == '(') {
i++;
ll res = f();
i++;
return res;
}
}
ll f() {
ll res = g();
while (1) {
if (S[i] == '+') {
i++;
res += g();
}
else if (S[i] == '-') {
i++;
res -= g();
}
else return res;
}
}
//---------------------------------------------------------------------------------------------------
int main() {
cin >> S;
cout << f() << endl;
return 0;
}