수학1 1193번 분수찾기
X가 주어졌을 때 X번째 분수를 구하는 프로그램 작성하시오
#include <iostream>
using namespace std;
int main() {
int low = 1, high = 1, limit = 2, ans, count = 1;
//두 번째 줄부터 반복하므로 limit=2, count=1
cin >> ans;
while (count != ans)
{
high = 1; low = limit; count++; //각 줄 초기화
while (limit != high) { //짝수 번째 화살표
if (count == ans) break;
high++; low--; count++;
}
if (count == ans) break;
limit++; //분모 혹은 분자값 1씩 증가
high = limit; low = 1; count++; //각 줄 초기화
while (limit != low) { //홀수 번째 화살표
if (count == ans) break; //사용자가 찾고자 하는 수
high--; low++; count++;
}
if (count == ans) break;
limit++; //분모 혹은 분자값 1씩 증가
}
cout << high << "/" << low;
}