結果
問題 | No.154 市バス |
ユーザー |
|
提出日時 | 2018-09-13 13:29:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 1,954 ms |
コンパイル使用メモリ | 104,064 KB |
実行使用メモリ | 21,760 KB |
最終ジャッジ日時 | 2024-07-01 04:22:10 |
合計ジャッジ時間 | 1,751 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
コンパイルメッセージ
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());// テストケース文字列を1文字ずつ判定for (int i = 0; i < Num_T; i++){// テストケース文字列 "S"string str_S = Console.ReadLine();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";}}}}