結果

問題 No.154 市バス
コンテスト
ユーザー hirakich1048576
提出日時 2016-07-10 12:59:01
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 850 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 32,092 KB
最終ジャッジ日時 2026-02-23 21:50:09
ジャッジサーバーID
(参考情報)
judge5 / 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);
      |                 ^~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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;
}


0