結果

問題 No.708 (+ー)の式
ユーザー stkchpstkchp
提出日時 2018-07-09 22:24:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 69,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 21:02:16
合計ジャッジ時間 1,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

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

	int r = 0;
	bool m = false;
	bool i = false;
	int ir = 0;
	bool im = false;

	for (auto c : str)
	{
		if (!i)
		{
			// インデントされていない
			if ('0' <= c && c <= '9')
			{
				int n = c - '0';
				m ? r -= n : r += n;
			}
			else if (c == '+') m = false;
			else if (c == '-') m = true;
			else if (c == '(')
			{
				i = true;
				ir = 0;
				im = false;
			}
		} 
		else
		{
			// インデントされている
			if ('0' <= c && c <= '9')
			{
				int n = c - '0';
				im ? ir -= n : ir += n;
			}
			else if (c == '+') im = false;
			else if (c == '-') im = true;
			else if (c == ')')
			{
				i = false;
				m ? r -= ir : r += ir;
			}
		}
	}

	cout << r << endl;

	return 0;
}
0