結果

問題 No.193 筒の数式
ユーザー hotpepsihotpepsi
提出日時 2015-11-10 00:38:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 664 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 62,216 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 15:28:46
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int eval(string s) {
	if (s[0] < '0' || s[s.length() - 1] < '0') {
		return -(1 << 30);
	}
	int tot = 0;
	int sign = 1;
	int val = 0;
	for (char c : s) {
		if (c == '+') {
			tot += val * sign;
			sign = 1;
			val = 0;
		} else if (c == '-') {
			tot += val * sign;
			sign = -1;
			val = 0;
		} else {
			val = val * 10 + c - '0';
		}
	}
	return tot + val * sign;
}

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int ans = -(1 << 30);
	for (int i = 0; i != s.length(); ++i) {
		ans = max(ans, eval(s.substr(i) + s.substr(0, i)));
	}
	cout << ans << endl;
	return 0;
}
0