結果

問題 No.193 筒の数式
ユーザー latte0119latte0119
提出日時 2015-04-26 22:39:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 146,888 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 12:11:06
合計ジャッジ時間 2,145 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef string::const_iterator state;


int number(state &s){
    int ret=0;
    while(isdigit(*s)){
        ret*=10;
        ret+=*s-'0';
        s++;
    }
    return ret;
}

int expression(state &s){
    int ret=number(s);
    while(true){
        if(*s=='+'){
            s++;
            ret+=number(s);
        }
        else if(*s=='-'){
            s++;
            ret-=number(s);
        }
        else break;
    }
    return ret;
}

int solve(string str){
    state b=str.begin();
    return expression(b);
}

int main(){
    string str;
    cin>>str;
    int ma=0;
    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("%d\n",ma);
    return 0;
}
0