結果
問題 |
No.154 市バス
|
ユーザー |
![]() |
提出日時 | 2016-07-10 12:59:01 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 850 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 22,016 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-13 08:38:00 |
合計ジャッジ時間 | 853 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 7 WA * 1 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:64:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | scanf("%d", &n); | ^~~~~~~~~~~~~~~ main.c:67:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | scanf("%s", s); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> #include <stdlib.h> #define N_MAX 1000 char s[N_MAX + 1]; char t[N_MAX + 1]; int answer; int i, j, n; int abs(int x){ return (x > 0) ? x : -x; } int min(int x, int y){ return (x > y) ? y : x; } int comp (int *x, int *y) { return *y - *x; } int solve(){ char *p; int w, g, r; int finally; w = g = r = 0; for (p = s; *p; p++) { switch (*p) { case 'W': w++; finally = 2; break; case 'G': g++; if (g > w) return 0; finally = min(finally, 1); break; case 'R': r++; if (r > g) return 0; finally = min(finally, 0); break; } } if (g == r && g && !finally) { return 2; } else { return 0; } } int main(void){ const char imp[] = "impossible"; scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%s", s); puts(imp+solve()); } return 0; }