結果
問題 | No.193 筒の数式 |
ユーザー |
|
提出日時 | 2015-12-15 15:33:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 786 bytes |
コンパイル時間 | 1,468 ms |
コンパイル使用メモリ | 160,216 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 13:04:21 |
合計ジャッジ時間 | 2,032 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) typedef string::const_iterator st; int num(st &s){ int ret = 0; while(isdigit(*s)){ ret = ret * 10 + (*s - '0'); s++; } return ret; } int expr(st &s){ int ret = num(s); while(1){ if(*s == '+'){ s++; ret += num(s); } else if(*s == '-'){ s++; ret -= num(s); } else break; } return ret; } int calc(string s){ st ss=s.begin(); return expr(ss); } int main(){ string s; cin >> s; int res = INT_MIN, n = s.length(); REP(i,n){ if(isdigit(*s.begin()) && isdigit(*(s.end()-1))){ res = max(res, calc(s)); } s.push_back(s.front()); s.erase(s.begin()); } cout << res << endl; }