結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2018-11-05 02:28:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 915 bytes |
コンパイル時間 | 1,745 ms |
コンパイル使用メモリ | 166,720 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 02:00:42 |
合計ジャッジ時間 | 2,177 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); } template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } using Itr = string::const_iterator; int expr(Itr& itr); int num(Itr& itr); int expr(Itr& itr) { int res = num(itr); while (true) { if (*itr == '*') res += num(++itr); else if (*itr == '+') res *= num(++itr); else break; } return res; } int num(Itr& itr) { int res = 0; while (isdigit(*itr)) { res = res * 10 + *itr - '0'; ++itr; } return res; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); string s; cin >> s; Itr itr = cbegin(s); cout << expr(itr) << '\n'; }