문제: https://school.programmers.co.kr/learn/courses/30/lessons/389478
본인이 몇번째 줄, 몇번째 위치인지 알아야한다. + 마지막 상자가 몇번째 줄, 몇번째 위치인지 알아야한다.
만약 상자가 w로 나누었을때 나머지가 0이라면 위치를 조정시킬 필요가 있다.
→ col == 0 → row— , col = w
자신의 위로 몇줄이 있는지 알아야한다.
마지막 줄에 자신의 col이 존재하는지 알아야한다.
class Solution {
public int solution(int n, int w, int num) {
int answer = 0;
int row = num / w + 1 ;
int col = num % w;
if(col == 0){
row--;
col = w;
}
int limitRow = n / w + 1;
int limitCol = n % w;
if(limitCol == 0){
limitRow--;
limitCol = w;
}
boolean even = true;
// 진행방향 확인
int curDir = 0; // 0 우 1 좌
int numDir = 0;
if(row % 2 == 0) curDir = 1;
if(limitRow % 2 == 0) numDir = 1;
System.out.println(col + " " + limitCol);
if(curDir == numDir){
answer = limitRow - row + 1;
System.out.println(col + " " + limitCol);
if(col > limitCol) answer--;
}else{
answer = limitRow - row + 1;
col = w - col + 1;
if(col > limitCol) answer--;
}
return answer;
}
}
```