結果
問題 |
No.49 算数の宿題
|
ユーザー |
![]() |
提出日時 | 2023-10-10 03:28:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 864 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 107,500 KB |
最終ジャッジ日時 | 2025-02-17 06:35:38 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include<iostream> #include<iomanip> #include<string> #include<algorithm> #include<vector> #include<set> #include<list> #include<queue> #include<math.h> #include<bitset> using ll = long long; using namespace std; int main(){ string s, op1 = "", op2 =""; cin >> s; ll sum1 = 0, tmp; bool first = true; for (int i = 0; i < s.size(); i++){ if (s[i] == '*' || s[i] == '+'){ op2 = op1; op1 = ""; op1 += s[i]; tmp = stoll(s.substr(0, i)); s = s.substr(i+1); i = 0; if (first){ sum1 += tmp; first = false; continue; } if (op2 == "*") sum1 += tmp; else sum1 *= tmp; } } if (op1 == "*") sum1 += stoll(s); else sum1 *= stoll(s); cout << sum1 << endl; }