結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
chakku
|
| 提出日時 | 2016-04-06 01:20:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,004 bytes |
| コンパイル時間 | 660 ms |
| コンパイル使用メモリ | 67,872 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 01:50:21 |
| 合計ジャッジ時間 | 1,262 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX/3
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
void func(int& ans,int& n,char op){
if(op=='+') ans = ans * n;
else ans = ans + n;
}
int main(){
string s; cin>>s;
int ans = 0;
int t = 0;
char op = '*';
for(int i=0;i<s.size();i++){
if('0'<=s[i] and s[i]<='9'){
t = t * 10 + s[i]-'0';
}
else if(s[i]=='*'){
func(ans,t,op);
op = '*';
t=0;
}
else if(s[i]=='+'){
func(ans,t,op);
op = '+';
t=0;
}
}
func(ans,t,op);
cout << ans << endl;
}
chakku