結果
| 問題 | 
                            No.154 市バス
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-05-26 05:19:14 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 873 bytes | 
| コンパイル時間 | 458 ms | 
| コンパイル使用メモリ | 59,300 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-13 07:23:44 | 
| 合計ジャッジ時間 | 1,355 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 7 WA * 1 | 
ソースコード
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
using namespace std;
bool judge(string);
int main(int argc, char *argv[]) {
	int T;
	string pattern;
	cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> pattern;
		cout << (judge(pattern) ? "possible" : "impossible") << endl;
	}
}
bool judge(string s) {
	int numOfWhite = 0;
	int numOfGreen = 0;
	int lastW = -1;
	int lastG = -1;
	int len = s.length();
	char c[1001];
	strcpy(c, s.c_str());
	for (int i = 0; i < len; i++) {
		if (c[i] == 'W') {
			numOfWhite++;
			lastW = i;
		} else if (c[i] == 'G') {
			if (numOfWhite < 1) {
				return false;
			}
			numOfGreen++;
			lastG = i;
		} else {
			if (numOfGreen > 0) {
				numOfWhite--;
				numOfGreen--;
			} else {
				return false;
			}
		}
	}
	if (numOfGreen != 0) {
		return false;
	}
	if (lastW > lastG) {
		return false;
	}
	return true;
}