結果

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

ソースコード

diff #

#include<iostream>
#include<string>
using namespace std;
int ans, tmp, op;

void calc()
{
	if (op) ans *= tmp;
	else ans += tmp;
	tmp = 0;
}
int main()
{
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == '*'){
			calc();
			op = 0;
		}
		else if (s[i] == '+'){
			calc();
			op = 1;
		}
		else{
			tmp *= 10;
			tmp += s[i] - '0';
		}
	}
	calc();
	cout << ans << endl;
	return 0;
}
0