



[ 접근 방법 ]
1. 가로 x 세로 배열을 직접 간단하게 그려보았다.
2. 막대 길이만큼 1을 반복한다.
3. 방향은 1이면 세로 0이면 가로다.
4. 좌표는 0 ~ 4 x 0 ~4칸이므로, 우리가 입력하는수는 1 3 일경우 0 2의 위치라서 x와 y에 각각 -1을 해준다.
5. 가로면 y를 증가시키고 세로면 x를 증가시킨다.
package CodeUp;
import java.util.Scanner;
public class CodeUp1098 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int height = sc.nextInt();
int width = sc.nextInt();
int n = sc.nextByte();
int array [] [] = new int [height] [width];
for(int i = 0; i < n ; i++){
int stick_length = sc.nextInt();
int direction = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
for(int k = 0; k < stick_length; k++){
if(direction == 1){
array [x-1+k] [y-1] = 1;
}
else{
array [x-1] [y-1+k] = 1;
}
}
}
for (int i = 0; i < height; i++) {
for (int k = 0; k < width; k++) {
System.out.printf("%d ",array[i] [k]);
}
System.out.println();
}
}
}'알고리즘' 카테고리의 다른 글
| [Algorithm]에라토스테네스의 체 자바풀이 소수찾기 백준 1929번 문제 (0) | 2023.01.11 |
|---|---|
| [코드업 1099번] 자바 풀이 성실한 개미 (0) | 2021.02.28 |
| [코드업 1091번 자바] [기초-1차원배열] 이상한 출석 번호 부르기1 (0) | 2021.01.30 |
| [코드업 자바 1086번 문제] 그림 파일 저장용량 계산하기 (0) | 2021.01.29 |
| [코드업 1082번 자바] 16진수 구구단 (0) | 2021.01.26 |