모든 일상

C# 2566번 문제 최댓값 본문

코딩 공부/C#

C# 2566번 문제 최댓값

통통푸린 2023. 1. 9. 16:15
728x90
반응형

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[,] arr = new string[9, 9];
            int max = int.MinValue; // 처음에 0으로 했다가 틀렸습니다, 나와서 한참 찾았네요 ㅠㅠ
            int y_loc= 0, x_loc = 0;

            for (int i = 0; i<9; i++)
            {
                string[] buff = Console.ReadLine().Split();
                for (int j = 0; j<9; j++)
                {
                    arr[i, j] = buff[j];
                }
            }

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if(max < int.Parse(arr[i,j]))
                    {
                        max = int.Parse(arr[i, j]);
                        x_loc = j+1; // 배열이 0부터 시작해서 +1 해줌
                        y_loc = i+1;
                    }
                }
            }
            Console.WriteLine(max);
            Console.WriteLine(y_loc + " " + x_loc);
        }
    }
}

728x90
반응형