백준 7단계 - 2차원 배열

이상훈·2023년 3월 16일
0

2738번

import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(bf.readLine());
		int N = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());

		int[][] arr1 = new int[N][M];
		int[][] arr2 = new int[N][M];

		for (int i = 0; i<N; i++) {
			st = new StringTokenizer(bf.readLine());

			for (int j = 0; j<M; j++) {
				arr1[i][j] = Integer.parseInt(st.nextToken());
			}
		}

		for (int i = 0; i<N; i++) {
			st = new StringTokenizer(bf.readLine());

			for (int j = 0; j<M; j++) {
				arr2[i][j] = Integer.parseInt(st.nextToken());
			}
		}

		for (int i = 0; i<N; i++) {
			for (int j = 0; j<M; j++) {
				System.out.print(arr1[i][j]+arr2[i][j]+ " ");
			}
            System.out.println();
		}

	}
}
별찍기와 흡사하다

2566번

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int[][] arr = new int[9][9];
		int max = -1;
		int k = 0;
		int l = 0;
		for (int i = 0; i<9; i++) {
			st = new StringTokenizer(bf.readLine());
			for (int j = 0; j<9; j++) {
				arr[i][j] = Integer.parseInt(st.nextToken());
				if (max < arr[i][j]) {
					max =arr[i][j];
					k = i+1;
					l = j+1;
				}
			}
		}
		System.out.println(max);
		System.out.println(k+" "+l);

	}
}
max를 입력받을 수의 범위보다 작게 설정하자.

10798번

import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		char[][] arr = new char[5][15];

		for (int i = 0; i<5; i++) {
			String text = bf.readLine();
			for (int j = 0; j<text.length(); j++) {
				arr[i][j] = text.charAt(j);
			}
		}
		for (int j = 0; j<15; j++) {
			for (int i = 0; i<5; i++) {
            	// char 배열의 빈값은 0이다.
				if (arr[i][j] == 0) {
					continue;
				} else {
					System.out.print(arr[i][j]);
				}
			}
		}
	}
}

2563번

import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int num = Integer.parseInt(bf.readLine());

		int[][] arr = new int[101][101];
		for (int i = 0; i<num; i++) {
			st = new StringTokenizer(bf.readLine());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			for (int j = y; j<y+10; j++) {
				for (int k = x; k<x+10; k++) {
					arr[j][k] += 1;
				}
			}
		}
		int sum = 0;
		for (int i = 1; i<101; i++) {
			for (int j = 1; j<101; j++) {
//				System.out.print(arr[i][j]);
				if (arr[i][j] != 0) {
					sum += 1;
				}
			}
//			System.out.println();
		}
		System.out.println(sum);
	}
}

0개의 댓글