LoginSignup
6
8

More than 5 years have passed since last update.

季節外れのズンドコ(C#)

Posted at

某twitterに流れてきたズンドコをC#で書いてみました。
下記のコードは何の工夫もなく機能を満たすように書いたもの。
直近5つを保持するのにQueueを使ったのが唯一の工夫っぽい点。

zundoko.cs
using System;
using System.Collections.Generic;

namespace zundoko
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = new Queue<string>();
            var r = new Random();
            const string z = "ズン";
            const string d = "ドコ";
            const string g = z + z + z + z + d;

            while (true)
            {
                q.Enqueue(r.Next(2) == 0 ? z : d);
                if (q.Count == 5)
                {
                    if (string.Join("", q) == g)
                    {
                        Console.WriteLine(g + "キ・ヨ・シ!");
                        break;
                    }
                    Console.Write(q.Dequeue());
                }
            }
        }
    }
}
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8