BaekJoon[C#]

2차원 배열 2738

wny0320 2022. 12. 21. 17:14

백준 온라인 코딩 문제풀이

https://www.acmicpc.net/

 

Baekjoon Online Judge

Baekjoon Online Judge 프로그래밍 문제를 풀고 온라인으로 채점받을 수 있는 곳입니다.

www.acmicpc.net

 

코드 참고

https://replit.com/@wny0320

 

wny0320 (박 상운)

Run code live in your browser. Write and run code in 50+ languages online with Replit, a powerful IDE, compiler, & interpreter.

replit.com

 

2738번에 대해 다룸

 


2738

using System;

namespace Farming_VS
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int[] inputInt = Array.ConvertAll(input, int.Parse);
            int[,] aArray = new int[inputInt[0], inputInt[1]];
            int[,] bArray = new int[inputInt[0], inputInt[1]];
            int[,] result = new int[inputInt[0], inputInt[1]];
            for(int col = 0; col < inputInt[0]; col++)
            {
                string[] buffer = Console.ReadLine().Split();
                for(int raw = 0; raw < inputInt[1]; raw++)
                {
                    aArray[col, raw] = int.Parse(buffer[raw]);
                }
            }
            for (int col = 0; col < inputInt[0]; col++)
            {
                string[] buffer = Console.ReadLine().Split();
                for (int raw = 0; raw < inputInt[1]; raw++)
                {
                    bArray[col, raw] = int.Parse(buffer[raw]);
                }
            }
            for (int col = 0; col < inputInt[0]; col++)
            {
                for (int raw = 0; raw < inputInt[1]; raw++)
                {
                    Console.Write(aArray[col, raw] + bArray[col, raw] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}

배열 둘을 받은 후 행과 열에 따라 반복문을 적용 시켰음

 

반복문을 통해 두 행렬을 덧셈해서 새로운 행렬에 저장한 후 출력하였다

 

배열의 행과 열에 대한 지식만 있다면 어렵지 않게 풀 수 있다

'BaekJoon[C#]' 카테고리의 다른 글

2차원 배열 2563  (0) 2022.12.23
2차원 배열 2566  (0) 2022.12.22
기본 수학 2단계 4948  (0) 2022.11.01
기본 수학 2단계 1929  (0) 2022.10.31
기본 수학 2단계 11653  (0) 2022.10.30