結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
Nagisa
|
| 提出日時 | 2016-07-24 21:52:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 740 bytes |
| コンパイル時間 | 1,772 ms |
| コンパイル使用メモリ | 174,132 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 01:53:12 |
| 合計ジャッジ時間 | 2,350 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
int main(){
string S;
cin >> S;
vector<int> N;
vector<string> M;
string temp = "";
REP(i,S.size()){
if(S[i]=='+'){
N.push_back(stoi(temp));
M.push_back("a");
temp = "";
}else if(S[i]=='*'){
N.push_back(stoi(temp));
M.push_back("b");
temp = "";
}
else{
temp += S[i];
}
}
N.push_back(stoi(temp));
int ans = N[0];
REP(i,M.size()){
if(M[i]=="a"){
ans *= N[i+1];
}else{
ans += N[i+1];
}
}
cout << ans << endl;
return 0;
}
Nagisa