結果

問題 No.49 算数の宿題
ユーザー ty70
提出日時 2015-06-10 17:43:24
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,593 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 88,336 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 01:45:29
合計ジャッジ時間 1,266 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cstdlib> // require abs exit atof atoi
#include <cstdio> // require scanf printf
#include <functional>
#include <numeric> // require accumulate
#include <cmath> // require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip> // require setw
#include <sstream> // require stringstream
#include <cstring> // require memset
#include <cctype> // require tolower, toupper
#include <fstream> // require freopen
#include <ctime> // require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
/*
No.49 宿
<> ::= <> '* or +' <> '* or +' ...
<> ::= ...
Howto https://gist.github.com/draftcode/1357281
*/
using namespace std;
typedef string::const_iterator State;
int number (State &ind ){
int res = 0;
while (isdigit(*ind ) ){
res *= 10;
res += (int)(*ind - '0' );
ind++;
} // end while
return res;
}
int expression (State &ind ){
int res = number (ind );
while (true ){
char op = *ind;
if (op == '*' ){
ind++;
res += number (ind );
}else
if (op == '+' ){
ind++;
res *= number (ind );
}else{
break;
} // end if
} // end whlie
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
string S; cin >> S;
State ind = S.begin();
int res = expression (ind );
cout << res << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0