結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
kapo
|
| 提出日時 | 2016-05-09 13:19:59 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 765 bytes |
| コンパイル時間 | 524 ms |
| コンパイル使用メモリ | 22,400 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-05 13:06:28 |
| 合計ジャッジ時間 | 1,138 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 5 |
コンパイルメッセージ
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);
| ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int i, j, k, len, cnt=1, x[10], y, sum=0;
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;
}
kapo