結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-10 14:26:13 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,816 bytes |
| コンパイル時間 | 1,026 ms |
| コンパイル使用メモリ | 104,192 KB |
| 実行使用メモリ | 17,792 KB |
| 最終ジャッジ日時 | 2024-12-29 15:15:57 |
| 合計ジャッジ時間 | 2,091 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 6 WA * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
namespace bus
{
class Program
{
static void Main(string[] args)
{
// テストケースの数 整数 "T"
int Num_T = int.Parse(Console.ReadLine());
// テストケース文字列 "S"
string str_S = Console.ReadLine();
// テストケース文字列を1文字ずつ判定
for (int i = 0; i < Num_T; i++)
{
Console.WriteLine(judgingLight(str_S));
}
}
static string judgingLight(string str)
{
int wht = 0; // 白色カウント
int grn = 0; // 緑色カウント
int red = 0; // 赤色カウント
char pre = ' '; // 直前の色を記憶
// 一文字ずつ検索する
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'W')
{
wht++;
}
if (str[i] == 'G')
{
grn++;
}
if (str[i] == 'R')
{
red++;
}
else
{
pre = str[i];
}
// "白 < 緑"もしくは"緑 < 赤" になるタイミングは絶対に存在しない
if (wht < grn || grn < red)
{
return "impossible";
}
}
// 最後の直前が "G(緑)" かつ "緑と赤の数が同じ"ときのみ存在する
if (pre == 'G' && grn == red)
{
return "possible";
}
else
{
return "impossible";
}
}
}
}