Published on

๐Ÿ› ๏ธ[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]-๋ชจ์˜๊ณ ์‚ฌ ๋ฌธ์ œ

Authors

๐Ÿ“–๋ฌธ์ œ ์„ค๋ช…


์ˆ˜ํฌ์ž๋Š” ์ˆ˜ํ•™์„ ํฌ๊ธฐํ•œ ์‚ฌ๋žŒ์˜ ์ค€๋ง์ž…๋‹ˆ๋‹ค. ์ˆ˜ํฌ์ž ์‚ผ์ธ๋ฐฉ์€ ๋ชจ์˜๊ณ ์‚ฌ์— ์ˆ˜ํ•™ ๋ฌธ์ œ๋ฅผ ์ „๋ถ€ ์ฐ์œผ๋ ค ํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜ํฌ์ž๋Š” 1๋ฒˆ ๋ฌธ์ œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ๋ฌธ์ œ๊นŒ์ง€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฐ์Šต๋‹ˆ๋‹ค.

1๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
2๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...
3๋ฒˆ ์ˆ˜ํฌ์ž๊ฐ€ ์ฐ๋Š” ๋ฐฉ์‹: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...

1๋ฒˆ ๋ฌธ์ œ๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ๋ฌธ์ œ๊นŒ์ง€์˜ ์ •๋‹ต์ด ์ˆœ์„œ๋Œ€๋กœ ๋“ค์€ ๋ฐฐ์—ด answers๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์€ ๋ฌธ์ œ๋ฅผ ๋งžํžŒ ์‚ฌ๋žŒ์ด ๋ˆ„๊ตฌ์ธ์ง€ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์กฐ๊ฑด

  • ์‹œํ—˜์€ ์ตœ๋Œ€ 10,000 ๋ฌธ์ œ๋กœ ๊ตฌ์„ฑ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฌธ์ œ์˜ ์ •๋‹ต์€ 1, 2, 3, 4, 5์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
  • ๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ์‚ฌ๋žŒ์ด ์—ฌ๋Ÿฟ์ผ ๊ฒฝ์šฐ, returnํ•˜๋Š” ๊ฐ’์„ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด์ฃผ์„ธ์š”.

โœ๏ธ๋ฌธ์ œ ํ’€์ด


์ด๋ฒˆ ๋ฌธ์ œ์˜ ์ฃผ์˜์‚ฌํ•ญ์€ answers๊ฐ€ ๊ฐ€๋ณ€์ ์ด๊ณ  ๊ฐ ์ˆ˜ํฌ์ž๋“ค์˜ ์ฐ๋Š” ๋ฐฉ์‹์ด ๊ณ ์ •์ ์ด๋ผ๋Š” ์ ์— ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ, ์ฐ๋Š” ๋ฐฉ์‹์˜ ๊ทœ์น™์„ฑ์„ ๋ฐ”ํƒ•์œผ๋กœ ๋“ค์–ด์˜ฌ answers ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์นด์šดํŒ… ํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ!

โŒจ๏ธํ’€์ด ์ฝ”๋“œ


#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> answers) {
    int MAX_NUM = answers.size();
    int biggest;
    vector<int> returns;
    int student[3] = { 0, 0, 0 };
    int temparray[5] = {3, 1, 2, 4, 5};

    // 1๋ฒˆ ์ˆ˜ํฌ์ž ์ •๋‹ต ๋น„๊ต
    for (int i = 0; i < MAX_NUM; i++) {
        if (answers[i] == (i % 5) + 1) { student[0]++; }
    }

    // 2๋ฒˆ ์ˆ˜ํฌ์ž ์ •๋‹ต ๋น„๊ต
    for (int i = 0; i < MAX_NUM; i++) {
        if (i % 2 == 0 && answers[i] == 2) { student[1]++; }
        else {
            if (i % 8 == 1 && answers[i] == 1) { student[1]++; }
            if (i % 8 == 3 && answers[i] == 3) { student[1]++; }
            if (i % 8 == 5 && answers[i] == 4) { student[1]++; }
            if (i % 8 == 7 && answers[i] == 5) { student[1]++; }
        }
    }

    // 3๋ฒˆ ์ˆ˜ํฌ์ž ์ •๋‹ต ๋น„๊ต
    for (int i = 0; i < MAX_NUM; i++) {
        int index = i % 10;
        if(answers[i] == temparray[index/2]) { student[2]++; }
    }

    // ์ •๋‹ต ํšŸ์ˆ˜ ๋น„๊ต
    student[1] < student[2] ? biggest = student[2] : biggest = student[1];
    biggest < student[0] ? biggest = student[0] : biggest = biggest;

    for (int i = 0; i < 3; i++) {
        if (student[i] == biggest) { returns.push_back(i+1); }
    }
    return returns;
}

์ถœ์ฒ˜ : ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ชจ์˜๊ณ ์‚ฌ ๋ฌธ์ œ