結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-20 22:25:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 520 bytes |
| コンパイル時間 | 1,786 ms |
| コンパイル使用メモリ | 167,720 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 02:12:33 |
| 合計ジャッジ時間 | 2,863 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 RE * 5 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:10:13: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized]
10 | int pos;
| ^~~
main.cpp:23:9: warning: 'op' may be used uninitialized [-Wmaybe-uninitialized]
23 | if(op=='+') ans*=stoi(b);
| ^~
main.cpp:9:14: note: 'op' was declared here
9 | char op;
| ^~
ソースコード
#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;
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;
}