結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-20 22:27:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 526 bytes |
| コンパイル時間 | 1,650 ms |
| コンパイル使用メモリ | 167,576 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 02:12:36 |
| 合計ジャッジ時間 | 2,811 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 RE * 5 |
ソースコード
#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;
}