結果

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

int ans, temp, op;

void calc(){
	if (op) ans *= temp;
	else ans += temp;
	temp = 0;
}


int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.length(); i++)
	{
		if (S[i] == '*'){
			calc();//先に計算やるというのがみそ。operationはあとでやる
			op = 0;
		}
		else if (S[i] == '+'){
			calc();
			op = 1;//これが1は足し算の意味。それはifで今度おきた、数字がなくなったときやる
		}
		else{//計算で数字出てくるたびに10倍してやった、その後足すと、
			temp *= 10; //stringから数字の計算2桁以上が可能になる。10ずつかけてやるのがみそ。10進数なら
			temp += S[i] - '0';//これでstring から、数字になおせれる。そしてtempに足してやる。
		}
	}
	calc();
	cout << ans << endl;
}
0