結果

問題 No.193 筒の数式
ユーザー hanorverhanorver
提出日時 2015-10-29 22:10:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 913 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 71,308 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 05:22:40
合計ジャッジ時間 1,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<algorithm>

int solve(std::string s) {
	std::queue<std::string> q;
	int num = 0;
	for (int i = 0; i < s.length(); i++) {
		if (!isdigit(s[i])) {
			if (i == 0 || i == s.length() - 1 || !isdigit(s[i + 1])) return -999999;
			q.push(std::to_string(num));
			q.push(std::to_string(s[i]));
			num = 0;

		} else num = num * 10 + (s[i] - '0');
	}
	q.push(std::to_string(num));

	num = std::stoi(q.front());q.pop();
	while (q.size()) {
		std::string d = q.front();q.pop();
		if (d == "43") num += std::stoi(q.front());
		else num -= std::stoi(q.front());
		q.pop();
	}
	return num;
}

int main() {
	std::string str;
	std::cin >> str;

	int max = -9999;
	for (int i = 0; i < str.length(); i++) {
		max = std::max(solve(str), max);
		char s = str.back();
		str.erase(str.end() - 1);
		str.insert(str.begin(), s);
	}
	std::cout << max << std::endl;
	return 0;
}
0