콘솔창 & 윈도우창/코딩 테스트

프로그래머스 LV.2 N ^ 2 배열 자르기

뽀또치즈맛 2025. 4. 3. 23:00

 
GitHub : https://github.com/kwon1232/CodingTest/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/2/87390.%E2%80%85n%EF%BC%BE2%E2%80%85%EB%B0%B0%EC%97%B4%E2%80%85%EC%9E%90%EB%A5%B4%EA%B8%B0

CodingTest/프로그래머스/2/87390. n^2 배열 자르기 at main · kwon1232/CodingTest

This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - kwon1232/CodingTest

github.com

 
 
 

 
 

#include <string>
#include <vector>

using namespace std;

vector<int> solution(int n, long long left, long long right) {
    vector<int> answer;
    
    int row = left / n;
    int col = left % n;
    int count = right - left + 1;
    for (int i = 1; i <= count; i++)
    {
        int num = max(row + 1, col + 1);
        answer.push_back(num);
        col++;
        if(col == n)
        {
            row++;
            col = 0;
        }
    }
    
    return answer;
}

https://school.programmers.co.kr/learn/courses/30/lessons/87390