結果

問題 No.193 筒の数式
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-12 02:10:49
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 733 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 25,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 14:13:38
合計ジャッジ時間 1,746 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>

int calc(char *s){
	int i;
	int num = 0;
	int sum =0;
	char symbol = '+';
	for(i=0;;i++){
		if( '0'<= s[i] && s[i] <= '9'){
			num *= 10;
			num += (s[i] - '0');
		}else{
			if(symbol == '+'){
				sum += num;
			}else{
				sum -= num;
			}
			num = 0;
			symbol = s[i];
		}
		
		if(s[i] == '\0'){break;}
	}
	
	return sum;
}

int main(void){
	int i,n;
	int ans = 	-20000000;
	char s[15];
	
	scanf("%s", s);
	
	for(n=0;s[n]!=0;n++);
	
	for(i=0;i<n;i++){
		int c,k;
		char tmp = s[0];
		for(k=0;k<n-1;k++){
			s[k] = s[k+1];
		}
		s[k] = tmp;
		
		if(s[0] == '+' || s[0] == '-' || s[n-1] == '+' || s[n-1] == '-'){
			continue;
		}
		c = calc(s);
		if(ans < c){
			ans = c;
		}
	}
	
	printf("%d\n", ans);
	return 0;
}
0