Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9297

C#でAtCoder Beginners Selection(ABC086C - Traveling)

$
0
0

準備

C#でAtCoderデビューのための準備
のあとで AtCoder Beginners Selection をやってみました。

問題文

ABC086C - Traveling
https://atcoder.jp/contests/abs/tasks/arc089_a

提出結果

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        string result = "Yes";
        int tBefore = 0;
        int xBefore = 0;
        int yBefore = 0;
        for (int i = 0; i < N; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            if (result != "No")
            {
                int t = Math.Abs(int.Parse(input[0]) - tBefore);
                int x = Math.Abs(int.Parse(input[1]) - xBefore);
                int y = Math.Abs(int.Parse(input[2]) - yBefore);
                if ((t - (x + y)) < 0)
                {
                    result = "No";
                }
                else if ((t - (x + y)) % 2 != 0)
                {
                    result = "No";
                }
                tBefore = t;
                xBefore = x;
                yBefore = y;

            }
        }

        Console.WriteLine($"{result}");

    }
}

テスト実行

image.png
image.png
image.png


Viewing all articles
Browse latest Browse all 9297

Trending Articles