結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2014-10-23 22:44:03 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 3,564 bytes |
コンパイル時間 | 961 ms |
コンパイル使用メモリ | 82,316 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:41:29 |
合計ジャッジ時間 | 1,360 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:136:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 136 | scanf("%s", S); | ~~~~~^~~~~~~~~
ソースコード
#define _CRT_SECURE_NO_WARNINGS#include <string>#include <vector>#include <algorithm>#include <numeric>#include <set>#include <map>#include <queue>#include <iostream>#include <sstream>#include <cstdio>#include <cmath>#include <ctime>#include <cstring>#include <cctype>#include <cassert>#include <limits>#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))#if defined(_MSC_VER) || __cplusplus > 199711L#define aut(r,v) auto r = (v)#else#define aut(r,v) typeof(v) r = (v)#endif#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)#define all(o) (o).begin(), (o).end()#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define mset(m,v) memset(m,v,sizeof(m))#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLusing namespace std;typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii;typedef long long ll; typedef vector<long long> vl; typedef pair<long long, long long> pll; typedef vector<pair<long long, long long> > vpll;typedef vector<string> vs; typedef long double ld;template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }namespace parse {typedef const char *Pos;struct ParseError {Pos p_;std::stringstream *ss_;ParseError(const Pos &p) : p_(p), ss_(new std::stringstream()) { }ParseError(const ParseError &that) : p_(0), ss_(0) { *this = that; }ParseError &operator=(const ParseError &that) {delete ss_;p_ = that.p_;ss_ = new std::stringstream(that.ss_->str());return *this;}~ParseError() { delete ss_; }template<typename T> ParseError &operator<<(const T &t) {*ss_ << t;return *this;}friend std::ostream &operator<<(std::ostream &o, const ParseError &e) {o << e.ss_->str() << " at: ";Pos q = e.p_;for (int k = 0; *q && k < 20; ++q, ++k)o << *q;if (*q) o << "...";else o << "(end of input)";return o;}};inline bool cond(bool b, Pos &p) {if (b) ++p;return b;}inline bool rewind(int k, bool b, Pos &p) {if (!b) p -= k;return b;}inline bool rw0(bool b, Pos &p) { return b; }inline bool rw1(bool b, Pos &p) { return rewind(1, b, p); }inline bool rw2(bool b, Pos &p) { return rewind(2, b, p); }inline bool optional(bool) { return true; }inline bool expect(bool b, const Pos &p) {if (!b) throw ParseError(p) << "parse error";return b;}inline bool char_(char c, Pos &p) {return cond(c == *p, p);}inline bool string_(const char *str, Pos &p) {Pos o = p;for (const char *s = str; *s; ++s, ++p) {if (*s != *p) {p = o;return false;}}return true;}};using namespace parse;bool natural(Pos &p, int &res) {if (!isdigit(*p)) return false;int c = 0;while (isdigit(*p)) {c = c * 10 + (*p - '0');++p;}res = c;return true;}bool expr(Pos &p, int &res) {if(!natural(p, res)) return false;while (*p == '+' || *p == '*') {char op = *p;++p;int operand;expect(natural(p, operand), p);if (op == '+')res *= operand;elseres += operand;}return true;}int main() {char *S = new char[101];scanf("%s", S);Pos p = S;int res;expr(p, res);cout << res << endl;return 0;}