結果

問題 No.708 (+ー)の式
ユーザー GBGB
提出日時 2018-12-20 01:57:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 64,060 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 00:19:36
合計ジャッジ時間 1,080 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0