結果
問題 | No.193 筒の数式 |
ユーザー |
![]() |
提出日時 | 2015-04-26 22:38:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 87,680 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 03:04:59 |
合計ジャッジ時間 | 1,518 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include<iostream>#include<sstream>#include<algorithm>#include<map>#include<set>#include<queue>#include<complex>#include<cstdio>#include<cstdlib>#include<cstring>// #define DEBUGusing namespace std;// typedef pair<int,int>P;// typedef complex<double>P;typedef long long int ll;typedef unsigned long long int ull;const int INF = 1e9;const double EPS=1e-9;int calc(string str){if(!isdigit(str[0]))return -INF;if(!isdigit(str[str.size()-1]))return -INF;vector<int>vec;vector<char>ope;bool flag = false;stringstream s;s << str;while(!s.eof()){if(flag){char c;s >> c;ope.push_back(c);flag = false;}else {int num;s >> num;vec.push_back(num);flag = true;}}int ret = vec[0];for(int i = 0 ; i < ope.size() ; i++){if(ope[i] == '+')ret += vec[i+1];else ret -= vec[i+1];}return ret;}int main(int argc, char *argv[]){string s;cin >> s;int res = -INF;for(int i = 0 ; i < s.size() ; i++){string tmp;for(int j = i ; ; j = (j + 1)%s.size() ){tmp += s[j];if(j == (i + (int)s.size() -1)%s.size())break;}res = max(res,calc(tmp));}cout << res << endl;return 0;}