알고리즘/BOJ

백준 9297번 Reducing Improper Fractions

꾸준함. 2021. 7. 4. 00:14

문제 링크입니다: https://www.acmicpc.net/problem/9297

 

9297번: Reducing Improper Fractions

For each case output the line “Case x:” where x is the case number, on a single line, followed by a space, and then proper fraction. Each fraction will be of the form “I N/D”, where I is the integer part, N is the numerator of the fractional part,

www.acmicpc.net

간단한 구현 문제였습니다.

 

#include <iostream>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int testCase;
cin >> testCase;
for (int t = 1; t <= testCase; t++)
{
int n, d;
cin >> n >> d;
int quotient = n / d;
int remainder = n % d;
cout << "Case " << t << ": ";
if (quotient && remainder)
{
cout << quotient << " " << remainder << "/" << d << "\n";
}
else if (quotient)
{
cout << quotient << "\n";
}
else if (remainder)
{
cout << remainder << "/" << d << "\n";
}
else
{
cout << 0 << "\n";
}
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 9299번 Math Tutoring  (0) 2021.07.04
백준 9298번 Ant Entrapment  (0) 2021.07.04
백준 9295번 주사위  (0) 2021.07.04
백준 9288번 More Dice  (0) 2021.07.04
백준 9286번 Gradabase  (0) 2021.07.03