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

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

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

728x90

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 0 ์ˆ˜ํ•™, ๋ฐ˜๋ณต๋ฌธ

 

์ฃผ์‚ฌ์œ„์˜ ๊ฐœ์ˆ˜

int solution(vector<int> box, int n) {
    int a = box[0]/n;
    int b = box[1]/n;
    int c = box[2]/n;
    int answer = a*b*c;
    return answer;
}

 

ํ•ฉ์„ฑ์ˆ˜ ์ฐพ๊ธฐ

int solution(int n) {
    int answer = 0;
    for(int i=4; i<=n; ++i){
        for(int j=2; j<i; ++j){
            if(i%j==0) {
                answer++;
                break;
            }
        }
    }
    return answer;
}

 

์ตœ๋Œ“๊ฐ’ ๋งŒ๋“ค๊ธฐ (1)

int solution(vector<int> numbers) {
    sort(numbers.begin(), numbers.end());
    int size = numbers.size();
    int answer = numbers[size-1] * numbers[size-2];
    return answer;
}

 

ํŒฉํ† ๋ฆฌ์–ผ

// ํ‹€๋ฆฐ์ฝ”๋“œ
int solution(int n) {
    int tmp=1;
    for(int i=1; i<n; ++i){
        tmp *= i;
        if(tmp>n) return i-1;
    }
    return 0;
}
  • ํ…Œ์ŠคํŠธ 1,2,3 ์‹คํŒจ…์™œํ‹€๋ฆฌ์ง€
    // ํ‹€๋ฆฐ์ฝ”๋“œ
    int solution(int n) {
        int tmp=1;
        for(int i=1; i<12; ++i){
            tmp *= i;
            if(tmp>n) return i-1;
        }
        return 0;
    }
    • ์ œํ•œ์‚ฌํ•ญ ๋•Œ๋ฌธ์— ๋‹ต์˜ ์ตœ๋Œ€๊ฐ’์ด 10์ด๋ฏ€๋กœ ๋ฒ”์œ„๋ฅผ 11์ดํ•˜(12๋ฏธ๋งŒ)๋กœ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.

→ for๋ฌธ i์˜ ๋ฒ”์œ„๋ฅผ ๊ณ ์น˜๋‹ˆ๊นŒ ๋งž์•˜๋‹ค!

int solution(int n) {
    int tmp=1;
    for(int i=1; i<12; ++i){
        tmp *= i;
        if(tmp>n) return i-1;
    }
    return 0;
}
  • ์ œํ•œ์‚ฌํ•ญ ๋•Œ๋ฌธ์— ๋‹ต์˜ ์ตœ๋Œ€๊ฐ’์ด 10์ด๋ฏ€๋กœ ๋ฒ”์œ„๋ฅผ 11์ดํ•˜(12๋ฏธ๋งŒ)๋กœ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.

 

728x90