C# 1436번 영화감독 숌

2022. 1. 10. 13:36C#/[백준] 브루트 포스

문제

코드 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int count = 1;
            int defaultValue = 666;

            while (N > count)
            {
                if (defaultValue.ToString().Contains("666"))
                {
                    count += 1;
                }
                defaultValue += 1;
            }
            
            Console.WriteLine(defaultValue - 1);            
        }
    }
}

//이 밑으로는 실패한 코드(규칙을 찾으려했다)

    //if(N == 1)
    //    Console.WriteLine(defaultValue);

    //while (N > check)
    //{
    //    check += 19;
    //    checkCount += 1;
    //}

    //defaultValue = defaultValue + 10000 * (checkCount - 1);
    //N = N - 19 * (checkCount - 1);


    //while (N > count)
    //{
    //    if (count < 6)
    //    {
    //        defaultValue += 1000;
    //        count += 1;
    //        continue;
    //    }
    //    else if (count == 6)
    //    {
    //        defaultValue += 994;
    //        count += 1;
    //        continue;
    //    }
    //    else if (count > 6 && count < 16)
    //    {
    //        defaultValue += 1;
    //        count += 1;
    //        continue;
    //    }
    //    else if (count == 16)
    //    {
    //        defaultValue += 997;
    //        count += 1;
    //        continue;
    //    }
    //    else if (count > 16 && count < 19)
    //    {
    //        defaultValue += 1000;
    //        count += 1;
    //        continue;
    //    }

    //}


    //Console.WriteLine(defaultValue);

코드 풀이 :

위 코드를 보면 //이 밑으로는 실패한 코드(규칙을 찾으려했다)가 있을 것이다. 내가 만든 코드는 10만 이하의 수까지만 적용이 된다. 이후부터는 적용되지 않는다.

따라서 666을 숫자로 보지 않고 ‘666’ 문자열로 보고 ‘666’을 포함할때마다 count하는 방식으로 해결했다.

ex) N=2일때 [defaultValue = 666, count = 1], [defaultValue = 1666, count = 2] 이므로 1666을 출력한다.

 

깃허브 :

https://github.com/CheongHo-Lee/Algorithm-Study

 

GitHub - CheongHo-Lee/Algorithm-Study: Algorithm Study For Coding Test

Algorithm Study For Coding Test. Contribute to CheongHo-Lee/Algorithm-Study development by creating an account on GitHub.

github.com

 

'C# > [백준] 브루트 포스' 카테고리의 다른 글

C# 1018번 체스판 다시 칠하기  (0) 2022.01.10
C# 7568번 덩치  (0) 2022.01.10
C# 2231번 분해합  (0) 2022.01.10
C# 2798번 블랙잭  (0) 2022.01.10