結果

問題 No.193 筒の数式
ユーザー latte0119latte0119
提出日時 2015-04-26 22:41:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 906 bytes
コンパイル時間 2,721 ms
コンパイル使用メモリ 147,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 12:14:38
合計ジャッジ時間 2,389 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0