結果
問題 | No.193 筒の数式 |
ユーザー |
![]() |
提出日時 | 2015-04-26 22:41:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 906 bytes |
コンパイル時間 | 1,400 ms |
コンパイル使用メモリ | 161,444 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 03:09:23 |
合計ジャッジ時間 | 2,129 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef string::const_iterator state;typedef long long ll;ll number(state &s){ll ret=0;while(isdigit(*s)){ret*=10;ret+=*s-'0';s++;}return ret;}ll expression(state &s){ll ret=number(s);while(true){if(*s=='+'){s++;ret+=number(s);}else if(*s=='-'){s++;ret-=number(s);}else break;}return ret;}ll solve(string str){state b=str.begin();return expression(b);}int main(){string str;cin>>str;ll ma=INT_MIN;for(int i=0;i<str.size();i++){rotate(str.begin(),str.begin()+1,str.end());if(!isdigit(*str.begin()))continue;if(!isdigit(*(str.end()-1)))continue;ma=max(ma,solve(str+"="));}printf("%lld\n",ma);return 0;}