반응형

1096번

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int[][] board = new int[19][19];

		int whiteCount = scan.nextInt();

		for (int i = 0; i < whiteCount; i++) {
			board[scan.nextInt() - 1][scan.nextInt() - 1] = 1;
		}

		for (int j = 0; j < 19; j++) {
			for (int k = 0; k < 19; k++) {
				System.out.print(board[j][k] + " ");
			}
			System.out.println();
		}

		scan.close();

	}
}

 

1097번

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int[][] board = new int[19][19];

		for (int i = 0; i < 19; i++) {
			String[] lineNumbers = br.readLine().split(" ");
			for (int j = 0; j < 19; j++) {
				board[i][j] = Integer.parseInt(lineNumbers[j]);
			}
		}

		int count = Integer.parseInt(br.readLine());

		for (int i = 0; i < count; i++) {
			String[] locates = br.readLine().split(" ");
			int row = Integer.parseInt(locates[0]) - 1;
			int col = Integer.parseInt(locates[1]) - 1;

			for (int j = 0; j < 19; j++) {
				if (board[j][col] == 0) {
					board[j][col] = 1;
				} else {
					board[j][col] = 0;
				}
			}

			for (int k = 0; k < 19; k++) {
				if (board[row][k] == 0) {
					board[row][k] = 1;
				} else {
					board[row][k] = 0;
				}
			}

		}

		for (int i = 0; i < 19; i++) {
			for (int j = 0; j < 19; j++) {
				bw.write(board[i][j] + " ");
			}
			bw.newLine();
		}

		bw.flush();
		bw.close();
	}
}

 

1098번

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		String[] inputWH = br.readLine().split(" ");
		int[][] board = new int[Integer.parseInt(inputWH[0])][Integer.parseInt(inputWH[1])];

		int barCount = Integer.parseInt(br.readLine());

		for (int i = 0; i < barCount; i++) {
			String[] barInfo = br.readLine().split(" ");
			int l = Integer.parseInt(barInfo[0]);
			int d = Integer.parseInt(barInfo[1]);
			int y = Integer.parseInt(barInfo[2]) - 1;
			int x = Integer.parseInt(barInfo[3]) - 1;

			if (d == 0) { // 가로막대
				for (int j = x; j < x + l; j++) {
					board[y][j] = 1;
				}
			} else { // 세로막대
				for (int j = y; j < y + l; j++) {
					board[j][x] = 1;
				}
			}

		}

		for (int[] y : board) {
			for (int x : y) {
				bw.write(x + " ");
			}
			bw.newLine();
		}

		bw.flush();
		bw.close();
	}
}

 

1099번

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	private static int x = 1, y = 1;
	private static int[][] board = new int[10][10];

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		for (int i = 0; i < 10; i++) {
			String[] line = br.readLine().split(" ");
			for (int j = 0; j < 10; j++) {
				board[i][j] = Integer.parseInt(line[j]);
			}
		}

		while (true) {
			if (board[x][y] == 2) {
				board[x][y] = 9;
				break;
			}
			moveRight();
		}

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				bw.write(board[i][j] + " ");
			}
			bw.newLine();
		}

		bw.flush();
		bw.close();
	}

	private static void moveRight() {

		board[x][y] = 9;

		if (board[x][y + 1] == 0 || board[x][y + 1] == 2) { // 오른쪽으로 이동 가능
			y = y + 1;
		} else { // 오른쪽으로 이동 불가
			moveDown();
		}
	}

	private static void moveDown() {

		if (board[x + 1][y] == 0 || board[x + 1][y] == 2) { // 아래쪽으로 이동 가능
			x = x + 1;
		} else { // 아래쪽으로 이동 불가
			board[x][y] = 2;
		}
	}

}

 

코드업 100제 끝~!!

 

반응형

+ Recent posts