結果

問題 No.154 市バス
ユーザー yuppe19 😺
提出日時 2015-04-26 08:43:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 1,700 ms
コンパイル使用メモリ 157,008 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-13 07:20:56
合計ジャッジ時間 1,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     int t;  scanf("%d", &t);
      |             ~~~~~^~~~~~~~~~
main.cpp:27:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         char s[1024]; scanf("%s", s);
      |                       ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

int check(char *s) {
    int sz = strlen(s);
    int w = 0, g = 0, r = 0;
    bool experience = false;
    for(int i=0; i<sz; i++) {
        switch(s[i]) {
        case 'W':
            experience = false, w++;
            break;
        case 'G':
            if(w < ++g) { return 0; }
            experience = true;
            break;
        case 'R':
            if(g < ++r) { return 0; }
            break;
        }
    }
    return experience && g == r;
}

int main(void) {
    int t;  scanf("%d", &t);
    for(int i=0; i<t; i++) {
        char s[1024]; scanf("%s", s);
        printf("%s\n", check(s) ? "possible" : "impossible");
    }
    return 0;
}
0