結果

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

ソースコード

diff #

#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>

using namespace std; 


int main(){

	string s;
	cin>>s;

	int res=0;
	int num=0;

	char c=' ';
	for(int i=0;i<s.size();i++){
		if('0'<=s[i] && s[i]<='9'){
			if(c==' ') res=res*10+s[i]-'0';
			else  num=num*10+s[i]-'0';
		}
		else if(c==' ') c=s[i];
		else if(c=='*') {res+=num; num=0; c=s[i];}
		else if(c=='+') {res*=num; num=0; c=s[i];}
	}

	if(c=='*') res+=num;
	else if(c=='+') res*=num;

	cout<<res<<endl;

	return 0;
}
0