結果
問題 | No.49 算数の宿題 |
ユーザー |
|
提出日時 | 2023-05-02 08:29:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,216 bytes |
コンパイル時間 | 656 ms |
コンパイル使用メモリ | 67,840 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 02:19:00 |
合計ジャッジ時間 | 1,268 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <iostream>#include <string>#include <stack>using namespace std;int main() {string S;cin >> S;int res = 0;string curnum = "";char curop = '\0';for (char c : S) {if (c == '*' || c == '+') {switch (curop) {case '*': {res += stoi(curnum);break;}case '+': {res *= stoi(curnum);break;}case '\0': {res = stoi(curnum);break;}default:break;}curnum = "";curop = c;} else {curnum += c;}}if (curnum != "") {switch (curop) {case '*': {res += stoi(curnum);break;}case '+': {res *= stoi(curnum);break;}case '\0': {res = stoi(curnum);break;}default:break;}}cout << res << endl;}