結果

問題 No.708 (+ー)の式
ユーザー CleyLCleyL
提出日時 2021-10-27 17:31:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 66,352 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-16 12:43:03
合計ジャッジ時間 1,531 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 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>
//<fac> ::= "(" < <exp> ")" | <digits>
//<exp>    ::= <digits> | <digits> ("+"|"-") <exp> | <fac>
long long num(State &begin);
long long exp(State &begin);
long long fac(State &begin);

long long parse(string s){
	State begin = s.begin();
	return fac(begin);
}
int main(){
	string s;cin>>s;
	cout << parse(s) << endl;
}
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 += fac(begin);
		}else if(*begin == '-'){
			begin++;
			ret -= fac(begin);
		}else{
			break;
		}
	}
	return ret;
}
long long fac(State &begin){
	for(;;){
		if(*begin == '('){
			begin++;
			int ret = exp(begin);
			begin++;
      return ret;
		}else{
			return exp(begin);
		}
	}
}
0