結果

問題 No.193 筒の数式
ユーザー bj_k28bj_k28
提出日時 2015-04-26 23:26:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,616 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 87,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 11:12:09
合計ジャッジ時間 1,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

string S;

int solve(int i){
	string s, s1, s2;
	int ans = INT_MIN / 4;
	s1 = S.substr(i);
	s2 = S.substr(0, i);
	s = s1 + s2;
	string digit = "";
	if(s[0] == '+' || s[0] == '-' || s[s.size() - 1] == '+' || s[s.size() - 1] == '-'){
		return ans;
	}
	rep(i, s.size()){
		if(s[i] == '+' || s[i] == '-') break;
		digit += s[i];
	}
	stringstream fs;
	fs << digit;
	fs >> ans;
	digit = "";
	rep(i, s.size()){
		if(s[i] == '+' || s[i] == '-'){
			REP(j, i + 1, s.size()){
				if(s[j] == '+' || s[j] == '-') break;
				digit += s[j];
			}
			stringstream ss;
			ss << digit;
			int d;
			ss >> d;
			if(s[i] == '+') ans += d;
			else ans -= d;
			digit = "";
		}
	}
	return ans;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int ans = INT_MIN / 4;
	cin >> S;
	rep(i, S.size()){
		ans = max(ans, solve(i));
	}
	cout << ans << endl;
	return 0;
}
0