結果

問題 No.708 (+ー)の式
ユーザー CleyLCleyL
提出日時 2020-03-12 13:23:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 66,320 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 22:09:32
合計ジャッジ時間 1,245 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cctype>
using namespace std;
using State = string::const_iterator;
class ParseError{};
//<digit>  ::= ("0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9")
//<digits> ::= <digit> | <digit> <digits>
//<factor> ::= "(" < <exp> ")" | <digits>
//<exp>    ::= <digits> | <digits> ("+"|"-") <exp>

long long num(State &begin){
	int ret = 0;
	while(isdigit(*begin)){
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}
long long exp(State &begin){
	int ret = num(begin);
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += num(begin);
		}else if(*begin == '-'){
			begin++;
			ret -= num(begin);
		}else{
			break;
		}
	}
	return ret;
}
long long fac(State &begin){
	for(;;){
		if(*begin == '('){
			begin++;
			int ret = exp(begin);
			begin++;
		}else{
			return num(begin);
		}
	}
}
long long parse(string s){
	State begin = s.begin();
	return exp(begin);
}
int main(){
	string s;cin>>s;
	cout << parse(s) << endl;
}
0