[BOJ] 2920번: 음계 (C#)

pilg0.gwak·2020년 7월 27일

BOJ

목록 보기
1/9
post-thumbnail

문제 링크: https://www.acmicpc.net/problem/2920


나는 나름 고민해서 짰는데 다른 사람들이 푼 거보니까 그냥 "1 2 3 4 5 6 7 8"이랑 "8 7 6 5 4 3 2 1"만 확인하고 아니면 mixed 반환하게 했더라는... 나도 이제 저런 꼼수 좀 써야겠다.

using System;
 
internal class ProblemSolving
{
    private static void Main()
    {
        var list = Console.ReadLine().Split();
        int? tmpNumber = null;
        var result = string.Empty;
        for (int i = 0; i < list.Length; i++)
        {
            var num = int.Parse(list[i]);
            if (tmpNumber == null)
            {
                tmpNumber = num;
                continue;
            }
 
            if (tmpNumber + 1 == num)
            {
                tmpNumber++;
                result = "ascending";
                continue;
            }
            else if (tmpNumber - 1 == num)
            {
                tmpNumber--;
                result = "descending";
                continue;
            }
            else
            {
                result = "mixed";
                break;
            }
        }
        Console.WriteLine(result);
    }
}

0개의 댓글