結果

問題 No.154 市バス
ユーザー hirakich1048576hirakich1048576
提出日時 2016-07-10 12:59:01
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 22,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 09:50:25
合計ジャッジ時間 943 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,248 KB
testcase_01 AC 8 ms
5,376 KB
testcase_02 AC 9 ms
5,376 KB
testcase_03 AC 8 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

#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