結果

問題 No.193 筒の数式
ユーザー kapokapo
提出日時 2016-05-09 13:26:59
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 773 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 14:55:23
合計ジャッジ時間 792 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 0 ms
5,376 KB
testcase_16 AC 0 ms
5,376 KB
testcase_17 AC 0 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:9:17: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[11]’ [-Wformat=]
    9 |         scanf("%s", &s);
      |                ~^   ~~
      |                 |   |
      |                 |   char (*)[11]
      |                 char *
main.c:9:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%s", &s);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

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

int main(void)
{
	int i, j, k, len, cnt=1, x[10], y, sum=-99999999;
	char s[11], s2[11], c, *a;
	scanf("%s", &s);
	len = (int)strlen(s);

	for( i = 0; i < len; i++) {
		for( j = 0; j < len-1; j++) {
			c = s[j];
			s[j] = s[j+1];
			s[j+1] = c;
		}

		strcpy(s2, s);
		if( s2[0] != '+' && s2[0]!= '-' && s2[len-1] != '+' && s2[len-1] != '-') {
			a = strtok(s2, "+-");
			x[0] = atoi(a);
			for( k = 1; a = strtok(NULL, "+-"); k++ ){
				x[k] = atoi(a);
			}


			y = x[0];
			for( k = 0; k < len ; k++ ) {
				if( s[k] == '+' ) {
					y += x[cnt];
					cnt++;
				} else if( s[k] == '-' ) {
					y -= x[cnt];
					cnt++;
				}
			}
			cnt = 1;
			if( y > sum ) sum = y;
		}
	}
	printf("%d\n", sum);

	return 0;
}
0