結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2016-04-26 10:59:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 711 ms |
コンパイル使用メモリ | 63,616 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:51:08 |
合計ジャッジ時間 | 1,358 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <iostream>#include <string>using namespace std;int main(void){string s;cin>>s;bool flag=true; //trueならば前後を足し算,falseならば前後を掛け算int ans=0,num=0;for(int i=0;i<s.size();i++){if(s[i]=='*'){if(flag) ans+=num;else ans*=num;flag=true; num=0;}else if(s[i]=='+'){if(flag) ans+=num;else ans*=num;flag=false; num=0;}else{num*=10; num+=s[i]-'0';}}if(flag) ans+=num;else ans*=num;cout<<ans<<endl;}