結果

問題 No.49 算数の宿題
ユーザー E31415926
提出日時 2016-04-03 21:03:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 489 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 55,764 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 01:50:20
合計ジャッジ時間 1,008 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
using namespace std;

int main()
{
	string s;
	int l, i, ans = 0, a = 0, b = 0;
	cin >> s;
	l = s.length();
	for (i = 0; i < l; i++) {
		if (s[i] >= '0' && s[i] <= '9') a = a * 10 + s[i] - '0';
		else if (s[i] == '*') {
			if (b == 0)ans += a;
			else ans *= a;
			b = 0;
			a = 0;
		}
		else if (s[i] == '+') {
			if (b == 0)ans += a;
			else ans *= a;
			b = 1;
			a = 0;
		}
	}
	if (b == 0)ans += a;
	else ans *= a;
	cout << ans << endl;
	return 0;
}
0