0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C#でAtCoder Beginners Selection(ABC049C - 白昼夢)

Posted at

####準備
[C#でAtCoderデビューのための準備]
(https://qiita.com/azumabashi/items/7aa9e4b77c10970cc30a)
のあとで AtCoder Beginners Selection をやってみました。

####問題文
ABC049C - 白昼夢
[https://atcoder.jp/contests/abs/tasks/arc065_a]
(https://atcoder.jp/contests/abs/tasks/arc065_a)

####提出結果

using System;
 
class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        // dream dreamer erase eraser
        string dm = "dream";
        string dmr = "dreamer";
        string er = "erase";
        string err = "eraser";
        int dml = dm.Length;
        int dmrl = dmr.Length;
        int erl = er.Length;
        int errl = err.Length;
        string chkS = S;
        string result = "YES";
        while (true)
        {
            if (chkS.Length >= dml)
            {
                if (chkS.Substring(chkS.Length - dml, dml) == dm)
                {
                    if (chkS.Length == dml)
                    {
                        break;
                    }
                    else
                    {
                        chkS = chkS.Substring(0, chkS.Length - dml);
                        continue;
                    }
                }
            }
            if (chkS.Length >= dmrl)
            {
                if (chkS.Substring(chkS.Length - dmrl, dmrl) == dmr)
                {
                    if (chkS.Length == dmrl)
                    {
                        break;
                    }
                    else
                    {
                        chkS = chkS.Substring(0, chkS.Length - dmrl);
                        continue;
                    }
                }
            }
            if (chkS.Length >= erl)
            {
                if (chkS.Substring(chkS.Length - erl, erl) == er)
                {
                    if (chkS.Length == erl)
                    {
                        break;
                    }
                    else
                    {
                        chkS = chkS.Substring(0, chkS.Length - erl);
                        continue;
                    }
                }
            }
            if (chkS.Length >= errl)
            {
                if (chkS.Substring(chkS.Length - errl, errl) == err)
                {
                    if (chkS.Length == errl)
                    {
                        break;
                    }
                    else
                    {
                        chkS = chkS.Substring(0, chkS.Length - errl);
                        continue;
                    }
                }
            }
            result = "NO";
            break;
        }
                 
        Console.WriteLine($"{result}");
    }
}

####テスト実行
image.png
image.png
image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?