모든 일상

C# 백준 2231번 문제 분해합 본문

코딩 공부/C#

C# 백준 2231번 문제 분해합

통통푸린 2023. 1. 12. 08:50
728x90
반응형

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            bool check = false;

            for (int i = 1; i<num; i++)
            {
                int buff = i;
                int result = i;

                while(buff > 0)
                {
                    result += buff % 10;       
                    buff /= 10;
                }

                if (result == num)
                {
                    Console.WriteLine(i);
                    check = true;
                    break;
                }
            }
            if (!check)
            {
                Console.WriteLine("0");
            }
        }
    }
}
728x90
반응형