結果

問題 No.193 筒の数式
ユーザー Mcpu3Mcpu3
提出日時 2018-10-21 21:06:28
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,108 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 20:22:07
合計ジャッジ時間 1,011 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void calc(char *operator, char operant[], int *sum)
{
	if (*operator == '+') *sum += atoi(operant);
	else *sum -= atoi(operant);
}

void push(char *x, char operant[], int *top)
{
	operant[*top] = *x;
	++*top;
	operant[*top] = '\0';
}

void shift(char S[], int *length)
{
	char tmp = S[*length - 1];
	int i;
	for (i = *length - 1; i > 0; --i) S[i] = S[i - 1];
	S[0] = tmp;
}

int main(void)
{
	char S[11], operant[10], operator;
	int length, top, sum, max = INT_MIN, i, j;
	scanf("%s", S);
	length = strlen(S);
	for (i = 0; i < length; ++i) {
		if (S[0] == '+' || S[0] == '-' || S[length - 1] == '+' || S[length - 1] == '-') continue;
		operator = '+';
		top = 0;
		sum = 0;
		for (j = 0; j < length; ++j) {
			if (S[j] == '+' || S[j] == '-') {
				calc(&operator, operant, &sum);
				operator = S[j];
				top = 0;
			}
			else push(&S[j], operant, &top);
		}
		calc(&operator, operant, &sum);
		if (max < sum) max = sum;
		shift(S, &length);
	}
	printf("%d", max);
	return 0;
}
0