結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2022-06-14 12:48:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,970 bytes |
コンパイル時間 | 1,048 ms |
コンパイル使用メモリ | 96,696 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 02:16:44 |
合計ジャッジ時間 | 1,488 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
// yukicodr// No.49//二次元可変配列//vector <vector <int>> mass;//vector <vector <int>> memo;//vector <int> memo;//#include "stdafx.h"#include <iostream>#include <vector>#include <list>//list#include <queue> //queue#include <set> //連想コンテナ(要素が自動でソートされる)、要素1つ(Key)、keyの重複ない、O(logN)#include <map> //連想コンテナ(要素が自動でソートされる)、要素2つ(Key,data)、keyの重複ない、dataは重複あり、O(logN)#include <unordered_set> //hash、O(1)#include <unordered_map> //hash、O(1)#include <algorithm>#include <iomanip>#include <cstring>#include <string>#include <climits>//#include <bits/stdc++.h>using namespace std;#define FOR(x,to) for(x=0;x<to;x++)#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))#define FMAX(a,b) ((a)>(b)?(a):(b))#define FMIN(a,b) ((a)<(b)?(a):(b))#define FCEIL(a,b) ((a)+(b)-1)/(b)typedef unsigned long long ULL;typedef signed long long SLL;queue<int> _queue;string S;int ans= 0;int gflag = -1; // 0:+, 1:*int first = 1;int main(){int top = 0;cin >> S;for (int i = 0; i < S.size(); i++){if (S[i] == '*'){string num_s = S.substr(top, i-top);top = i + 1;if (first){ans = atoi(num_s.c_str());first = 0;}else{if(gflag == 1)ans = ans * atoi(num_s.c_str());elseans = ans + atoi(num_s.c_str());}gflag = 0;}if (S[i] == '+'){string num_s = S.substr(top, i - top);top = i + 1;if (first){ans = atoi(num_s.c_str());first = 0;}else{if (gflag == 1)ans = ans * atoi(num_s.c_str());elseans = ans + atoi(num_s.c_str());}gflag = 1;}}string num_s = S.substr(top, S.size() - top);if (gflag == 1)ans = ans * atoi(num_s.c_str());elseans = ans + atoi(num_s.c_str());cout << ans;return 0;}