結果

問題 No.49 算数の宿題
ユーザー nnasennnasen
提出日時 2017-12-17 23:11:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 650 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 164,496 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:38:38
合計ジャッジ時間 2,149 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 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,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD 1000003
#define INF 100000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int ans = 0;
int t = 0;
bool c = true;

void f() {
	if (c) ans += t;
	else ans *= t;
	t = 0;
}


int main() {
	string n;
	cin >> n;
	for (int i = 0; i < SZ(n); ++i) {
		if (n[i] == '*') {
			f();
			c = true;
		}
		else if (n[i] == '+') {
			f();
			c = false;
		}
		else {
			t *= 10;
			t += n[i] - '0';
		}
	}
	f();
	cout << ans << endl;
}
0