結果

問題 No.708 (+ー)の式
ユーザー polylogK
提出日時 2018-06-30 10:14:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 166,780 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 00:50:57
合計ジャッジ時間 2,160 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int st = 0;
std::string s;

int func() {
	int ret = s[st] - '0';
	for(st++ ; st < s.size(); st += 2) {
		if(s[st] == '+') {
			if(s[st + 1] == '(') {
				st += 2;
				ret += func();
			} else {
				ret += s[st + 1] - '0';
			}
		} else if(s[st] == '-') {
			if(s[st + 1] == '(') {
				st += 2;
				ret -= func();
			} else {
				ret -= s[st + 1] - '0';
			}
		}
		
		if(s[st] == ')'){
			st--;
			return ret;
		}
	}
	
	return ret;
}

int main(){
	cin >> s;
	
	cout << func() << endl;
	return 0;
}
0