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
'๐ ์๊ณ ๋ฆฌ์ฆ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 6์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.16 |
---|---|
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 5์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.16 |
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 4์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.16 |
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 3์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.16 |
[PGS] Lv.0 (์ฝ๋ฉํ ์คํธ ์ ๋ฌธ) 1์ผ์ฐจ ๋ฌธ์ (0) | 2023.01.16 |