結果

問題 No.49 算数の宿題
ユーザー Shawn stayCShawn stayC
提出日時 2020-07-20 22:27:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 526 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 164,864 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:48:13
合計ジャッジ時間 2,766 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main(){
	string s; cin>>s;
	int k=s.size(), ans=0;
	string a,b;
	char op='+';
	int pos=0;
	rep(i,k){
		if(s[i]=='+'||s[i]=='*'){pos=i+1; op=s[i]; break;}
		else a+=s[i];
	}
	ans=stoi(a);
	for(int i=pos; i<k; i++){
		b+=s[i];
		if(s[i]=='+'||s[i]=='*'){
			if(op=='+') {ans*=stoi(b); op=s[i]; b=" ";}
			if(op=='*') {ans+=stoi(b); op=s[i]; b=" ";}
		}
	}
	if(op=='+') ans*=stoi(b);
	if(op=='*') ans+=stoi(b);
	cout<<ans<<" "<<endl;
}
0