結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2017-09-18 12:19:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 726 bytes |
コンパイル時間 | 933 ms |
コンパイル使用メモリ | 80,444 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:58:27 |
合計ジャッジ時間 | 1,392 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <iostream> #include <iomanip> #include <vector> int main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(2); std::string s; std::cin >> s; std::vector< int > number; std::vector< bool > isadd; for (auto c : s) { if (c=='*') isadd.push_back(true); else if (c=='+') isadd.push_back(false); else { if (number.size() == isadd.size()) number.push_back(c-'0'); else number[number.size()-1] = number[number.size()-1] * 10 + (c-'0'); } } int ans = number[0]; for (int i = 0; i < isadd.size(); ++i) { if (isadd[i]) ans += number[i+1]; else ans *= number[i+1]; } std::cout << ans << std::endl; return 0; }