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

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

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

728x90

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

 

๋‘ ์ˆ˜์˜ ๋‚˜๋ˆ—์…ˆ

// sol 1
int solution(int num1, int num2) {
    double answer = 0;
    double mod = 0;
    mod = modf((num1*1000)/num2, &answer);
    return (int)answer;
}
// sol 2
int solution(int num1, int num2) {
    double answer = (double)num1*1000/num2;
    return (int)answer;
}

์ˆซ์ž ๋น„๊ตํ•˜๊ธฐ

int solution(int num1, int num2) {
    if(num1==num2) return 1;
    return -1;
}

๋ถ„์ˆ˜์˜ ๋ง์…ˆ

vector<int> solution(int denum1, int num1, int denum2, int num2) {
    vector<int> answer;
    int min=0;
    int bottom = num1 * num2;
    int top = denum1 * num2 + denum2 * num1;
    for(int i=1; i<=top; ++i){
        if(top%i==0 && bottom%i==0) min = i;   // ์•ฝ๋ถ„์„ ์œ„ํ•ด์„œ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜ ๊ตฌํ•˜๊ธฐ
    }
    answer.push_back(top/min);
    answer.push_back(bottom/min);
    return answer;
}

๋ฐฐ์—ด ๋‘ ๋ฐฐ ๋งŒ๋“ค๊ธฐ

vector<int> solution(vector<int> numbers) {
    vector<int> answer;
    for(int i=0;i<numbers.size();++i){
        answer.push_back(numbers[i]*2);
    }
    return answer;
}

.

โœ๐Ÿป ์ •์ˆ˜์™€ ์†Œ์ˆ˜๋ฅผ ๋ถ„๋ฆฌํ•  ๋•Œ? → modf(num, &๋ชซ) = ๋‚˜๋จธ์ง€ ์†Œ์ˆ˜๊ฐ’ (๋ชจ๋‘ doubleํ˜•์ด์–ด์•ผ ํ•จ)

728x90