結果

問題 No.193 筒の数式
ユーザー nablaenergy_21nablaenergy_21
提出日時 2015-04-26 22:53:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 27,160 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-18 12:20:59
合計ジャッジ時間 964 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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++){
		printf("%d %d %d\n",v,t,s);
		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