結果
問題 | No.49 算数の宿題 |
ユーザー |
|
提出日時 | 2017-09-14 16:48:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,945 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 76,908 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:58:18 |
合計ジャッジ時間 | 1,341 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In member function ‘calc::op calc::parse_operator()’: main.cpp:82:37: warning: control reaches end of non-void function [-Wreturn-type] 82 | syntax_error("parse_operator"); | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <cmath>#include <string>#include <vector>#include <algorithm>#include <queue>#include <map>#include <functional>#include <set>#include <numeric>#include <stack>#include <utility>#include <time.h>//#include "util.h"using namespace std;typedef long long lint;typedef unsigned long long ull;typedef pair<lint, lint> Pii;#define PI 3.14159265358979323846#define EPS 1e-6#define MOD ((lint)1000000007)#define MIN(a,b) ((a)<(b)?(a):(b))#define MAX(a,b) ((a)>(b)?(a):(b))#define CHAR_BIT 8template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {cout << "{ }";return ostr;}cout << "{" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {cout << ", " << *itr;}cout << "}";return ostr;}class calc {private:string S;int pos;enum op { MUL, ADD };public:calc(string S) {this->S = S;pos = 0;}calc(string S, int pos) {this->S = S; this->pos = pos;}void syntax_error(string S) {cout << S << endl;exit(EXIT_FAILURE);}int parse_int() {if (S[pos] < '0' || '9' < S[pos])syntax_error("parse_int");int res = 0;while (pos < S.size() && '0' <= S[pos] && S[pos] <= '9') {res *= 10;res += S[pos] - '0';pos++;}return res;}op parse_operator() {if (S[pos] == '*') {pos++;return ADD;}else if (S[pos] == '+') {pos++;return MUL;}elsesyntax_error("parse_operator");}int calculate() {int res = parse_int();while (pos != S.size()) {op o = parse_operator();if (o == ADD)res += parse_int();elseres *= parse_int();}return res;}};int yuki0044(){string S;cin >> S;cout << calc(S).calculate() << endl;return 0;}int main(){//clock_t start, end;//start = clock();yuki0044();//end = clock();//printf("%d msec.\n", end - start);return 0;}