結果

問題 No.49 算数の宿題
ユーザー myantamyanta
提出日時 2017-05-10 23:19:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 666 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 40,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:37:07
合計ジャッジ時間 934 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<deque>


int main(void)
{
	char s[100+2];
	std::deque<int> num, op;

	while(scanf("%s", s)==1)
	{
		num.clear();
		op.clear();

		{
			char o[1+2];
			int p, n, v, r;
			for(p=0;;p+=n)
			{
				r=sscanf(s+p, "%d%1[+*]%n", &v, o, &n);
				if(r<=0) return 0;
				if(r!=2) break;
				num.push_back(v);
				op.push_back(o[0]);
			}
			num.push_back(v);
		}

		{
			int o, v;
			for(;!op.empty();)
			{
				o=op[0];
				op.pop_front();
				if(o=='+')
				{
					v=num[0]*num[1];
				}
				else
				{
					v=num[0]+num[1];
				}
				num.pop_front();
				num.pop_front();
				num.push_front(v);
			}
		}
		printf("%d\n", num[0]);
	}

	return 0;
}
0