結果
問題 | No.193 筒の数式 |
ユーザー | kapo |
提出日時 | 2016-05-09 13:26:59 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 22,528 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-05 13:06:34 |
合計ジャッジ時間 | 871 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
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=-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; }