結果
問題 | No.49 算数の宿題 |
ユーザー | ramia777 |
提出日時 | 2022-06-14 12:48:35 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,970 bytes |
コンパイル時間 | 855 ms |
コンパイル使用メモリ | 96,948 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-24 17:51:33 |
合計ジャッジ時間 | 1,614 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,384 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
ソースコード
// 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()); else ans = 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()); else ans = 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()); else ans = ans + atoi(num_s.c_str()); cout << ans; return 0; }