結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-21 21:13:01 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,142 bytes |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-19 03:29:18 |
| 合計ジャッジ時間 | 869 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#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] == '-') {
shift(S, &length);
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;
}