-
[백준 단계별로 풀어보기] 2차원 배열 with C#Development/Program Solving 2023. 9. 6. 21:46728x90
2738번: 행렬 덧셈
using System.Text; class Program { static void Main(string[] args) { string[] rowColumnCount = Console.ReadLine().Split(); var row = int.Parse(rowColumnCount[0]); var column = int.Parse(rowColumnCount[1]); var twoDimensionalArray = new int[row, column]; var twoDimensionalArray2 = new int[row, column]; var resultArray = new int[row, column]; for (int i = 0; i < row; i++) { var array = Console.ReadLine().Split(); for (var y = 0; y < column; y++) { twoDimensionalArray[i, y] = int.Parse(array[y]); } } for (int i = 0; i < row; i++) { var array = Console.ReadLine().Split(); for (var y = 0; y < column; y++) { twoDimensionalArray2[i, y] = int.Parse(array[y]); } } for (int i = 0; i < row; i++) { for (var y = 0; y < column; y++) { resultArray[i, y] = twoDimensionalArray[i, y] + twoDimensionalArray2[i, y]; } } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < row; i++) { for (var y = 0; y < column; y++) { if ((y + 1) % column == 0) { stringBuilder.Append(resultArray[i, y]); } else { stringBuilder.AppendFormat("{0} ", resultArray[i, y]); } } Console.WriteLine(stringBuilder); stringBuilder.Clear(); } } }
2566번: 최댓값
var twoDimensionalArray = new int[9, 9]; int max = 0; int row = 0; int column = 0; for (int i = 0; i < 9; i++) { var array = Console.ReadLine().Split(); for (var y = 0; y < 9; y++) { twoDimensionalArray[i, y] = int.Parse(array[y]); } } for (int i = 0; i < 9; i++) { for (var y = 0; y < 9; y++) { if (twoDimensionalArray[i, y] > max) { max = twoDimensionalArray[i, y]; row = i; column = y; } } } Console.WriteLine(max); Console.WriteLine($"{row + 1} {column + 1}");
10798번: 세로읽기
using System.Text; class Program { static void Main(string[] args) { var arr = new char[5][]; int row = 5; int column = 0; for (var i = 0; i < row; i++) { char[] inputArray = Console.ReadLine().ToCharArray(); arr[i] = inputArray; if (inputArray.Length > column) { column = inputArray.Length; } } StringBuilder stringBuilder = new StringBuilder(); for (var i = 0; i < column; i++) { for (var y = 0; y < row; y++) { if (arr[y].Length - 1 < i) continue; stringBuilder.Append(arr[y][i].ToString()); } } Console.WriteLine(stringBuilder); } }
728x90'Development > Program Solving' 카테고리의 다른 글
[백준 단계별로 풀어보기] 심화 1 with C# (0) 2023.07.11 [백준 단계별로 풀어보기] 문자열 with C# (0) 2023.07.11 [백준 단계별로 풀어보기] 1차원 배열 with C# (0) 2023.07.11 [백준 단계별로 풀어보기] 반복문 with C# (0) 2023.07.10 [백준 10829번] 이진수 변환 (feat. NodeJS) (0) 2021.02.05