๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 10์ผ์ฐจ ๋ฌธ์ œ

728x90

โœ๐Ÿป ๋ฒกํ„ฐ numbers ์™€ tmp ์—ฐ๊ฒฐํ•˜๊ธฐ (ํ•ฉ์น˜๊ธฐ) → numbers.insert( numbers.end(), tmp.begin(), tmp.end() )

โœ๐Ÿป ๋ฒกํ„ฐ์˜ ์ฒซ ์›์†Œ ์‚ญ์ œํ•˜๊ธฐ → v.erase( v.begin() )

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 0 ์กฐ๊ฑด๋ฌธ, ๋ฐฐ์—ด, ์ˆ˜ํ•™, ์‹œ๋ฎฌ๋ ˆ์ด์…˜

 

์ ์˜ ์œ„์น˜ ๊ตฌํ•˜๊ธฐ

int solution(vector<int> dot) {
    if(dot[0]>0 && dot[1]>0) return 1;
    if(dot[0]<0 && dot[1]>0) return 2;
    if(dot[0]<0 && dot[1]<0) return 3;
    if(dot[0]>0 && dot[1]<0) return 4;
}

2์ฐจ์›์œผ๋กœ ๋งŒ๋“ค๊ธฐ

vector<vector<int>> solution(vector<int> num_list, int n) {
    vector<vector<int>> answer;
    int size = num_list.size() / n;
    for(int i=0; i<size; ++i){
        vector<int> v;
        for(int j=0; j<n; ++j){
            v.push_back(num_list[0]);
            num_list.erase(num_list.begin());
        }
        answer.push_back(v);
    }
    return answer;
}

๊ณต ๋˜์ง€๊ธฐ

int solution(vector<int> numbers, int k) {
    int answer = 0;
    vector<int> tmp = numbers;
    while(1){
        if(numbers.size()>2*k) break;
        numbers.insert(numbers.end(), tmp.begin(), tmp.end());
    }
    answer = numbers[2*k - 2];
    return answer;
}

๋ฐฐ์—ด ํšŒ์ „์‹œํ‚ค๊ธฐ

vector<int> solution(vector<int> numbers, string direction) {
    vector<int> answer;
    int size = numbers.size();
    if(direction=="right"){
        answer.push_back(numbers[size-1]);
        for(int i=0; i<size-1; ++i){
            answer.push_back(numbers[i]);
        }
    }
    else if(direction=="left"){
        for(int i=1; i<size; ++i){
            answer.push_back(numbers[i]);
        }
        answer.push_back(numbers[0]);
    }
    return answer;
}

 

ํ‘ผ ๋ฌธ์ œ๋Š” ๋งŽ์€๋ฐ ์–ธ์ œ ๋‹ค ์˜ฌ๋ฆฌ์ง€..

728x90