// LV2. 행렬테두리 회전하기
public static int[] solution_matrix_rotation(int rows,int columns,int[][] queries){
int[][] matrix = new int[rows][columns];
IntStream.range(0,rows).forEach(i->IntStream.range(0,columns).forEach(j-> matrix[i][j] = i*columns+j+1));
return IntStream.range(0, queries.length).map(i -> rotate_matrix(rows,columns,matrix,queries[i])).toArray();
}
public static int rotate_matrix(int rows,int columns,int[][] matrix,int[] query){
int min = 10000;
int[][] copy_matrix = new int[rows][columns];
IntStream.range(0,copy_matrix.length).forEach(a -> System.arraycopy(matrix[a],0,copy_matrix[a],0,matrix[a].length));
int x_pos = query[1]-1, y_pos = query[0]-1;
do{
if(copy_matrix[y_pos][x_pos] < min) min = copy_matrix[y_pos][x_pos];
if (x_pos < query[3]-1 && y_pos == query[0]-1) matrix[y_pos][x_pos+1] = copy_matrix[y_pos][x_pos++];
else if (x_pos == query[3]-1 && y_pos < query[2]-1) matrix[y_pos+1][x_pos] = copy_matrix[y_pos++][x_pos];
else if (x_pos > query[1]-1 && y_pos == query[2]-1) matrix[y_pos][x_pos-1] = copy_matrix[y_pos][x_pos--];
else if (x_pos == query[1]-1 && y_pos >= query[0]-1) matrix[y_pos-1][x_pos] = copy_matrix[y_pos--][x_pos];
}while((query[1]-1 < x_pos && x_pos <= query[3]-1) || (query[0]-1 < y_pos && y_pos <= query[2]-1));
return min;
}