코딩 공부/C#

C# 백준 2564번 색종이 문제

통통푸린 2023. 2. 16. 17:14
728x90
반응형

100 X 100 이차원 배열을 생성하고 입력한 X, Y 값부터 + 10까지의 범위에 모두 "1"을 넣고

마지막에 1의 개수를 합이 곧 이 문제의 답이 된다. 

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

namespace ConsoleApplication2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            string[,] arr = new string[100,100];
            int cnt = 0;
            while (num > 0)  
            {
                string[] buff = Console.ReadLine().Split();
                int x = int.Parse(buff[0]);
                int y = int.Parse(buff[1]);
                num--;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        arr[x + i, y + j] = "1";
                    }
                }
            }

            for(int i = 0; i<100; i++)
            {
                for(int j = 0; j<100; j++)
                {
                    if (arr[i, j] == "1") cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}
728x90
반응형