結果

問題 No.193 筒の数式
ユーザー nablaenergy_21nablaenergy_21
提出日時 2015-04-26 22:53:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 996 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 27,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 12:21:00
合計ジャッジ時間 1,039 ms
ジャッジサーバーID
(参考情報)
judge13 / 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,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>

char S[21];
long long M;
long long ans;
long long max(long long a,long long b){
	if(a>b){return a;}else{return b;}
}

long long val(int a){
	long long v,t,s;
	long long i;
	char p;
	/*Sのa番目からM文字を読んで計算する*/
	if(S[a] == '+' || S[a] == '-'){return -100000000000;}
	if(S[a+M-1] == '+' || S[a+M-1] == '-'){return -100000000000;}

	v = 0;
	t = 0;
	s = 1;
	for(i=a;i<a+M;i++){
		p = S[i];
		if(p=='+'){
			if(s == 1){
				v = v + t;
			}else{
				v = v - t;
			}
			t = 0;
			s = 1;
		}else if(p=='-'){
			if(s == 1){
				v = v + t;
			}else{
				v = v - t;
			}
			t = 0;
			s = -1;
		}else{
			t = t * 10;
			t = t + (p - '0');
		}
	}
	if(s == 1){
		v = v + t;
	}else{
		v = v - t;
	}
	t = 0;
	s = 1;
	return v;
}


int main(void){
	long long i;
	scanf("%s",S);
	M = strlen(S);
	for(i=M;i<2*M;i++){
		S[i] = S[i-M];
	}
	S[2*M] = '\0';


	ans = -1000000000000;
	for(i=0;i<M;i++){
		ans = max(ans,val(i));
	}
	printf("%lld\n",ans);
}
0