結果

問題 No.193 筒の数式
ユーザー CleyLCleyL
提出日時 2020-03-12 11:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 976 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 67,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 19:44:59
合計ジャッジ時間 1,353 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 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>
//<exp>    ::= <digits> | <digits> ("+"|"-") <exp> | "(" <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 parse(string s){
	State begin = s.begin();
	return exp(begin);
}
int main(){
	string ss;cin>>ss;
	string s = ss+ss;
	long long ans = -10000000000;
	for(int i = 0; ss.size() > i; i++){
		if(isdigit(s[i]) && isdigit(s[i+ss.size()-1])){
			ans = max(ans,parse(s.substr(i,ss.size())));
		}
	}
	cout << ans << endl;
}
0