码迷,mamicode.com
首页 > 其他好文 > 详细

Kattis - mixedfractions

时间:2017-01-12 21:03:45      阅读:23      评论:0      收藏:0      [点我收藏+]

标签:str   tor   msu   math   -o   body   data   分数   ber   

Mixed Fractions

You are part of a team developing software to help students learn basic mathematics. You are to write one part of that software, which is to display possibly improper fractions as mixed fractions. A proper fraction is one where the numerator is less than the denominator; a mixed fraction is a whole number followed by a proper fraction. For example the improper fraction 27/12 is equivalent to the mixed fraction 2 3/12. You should not reduce the fraction (i.e. don’t change 3/12 to 1/4).

Input

Input has one test case per line. Each test case contains two integers in the range [1,2311][1,231−1]. The first number is the numerator and the second is the denominator. A line containing 0 00 0 will follow the last test case.

Output

For each test case, display the resulting mixed fraction as a whole number followed by a proper fraction, using whitespace to separate the output tokens.

Sample Input 1Sample Output 1
27 12
2460000 98400
3 4000
0 0
2 3 / 12
25 0 / 98400
0 3 / 4000

题意

把给出的分数化成整数和真分数的形式

代码

#include<bits/stdc++.h>
using namespace std;
int main() {
    long long n, m;
    while(cin >> n >> m) {
        if(n == m && n == 0)
            break;
        long long cnt = 0;
        if(n >= m) {
            cnt = n / m;
            n = n - cnt * m;
        }
        printf("%d %d / %d\n", cnt, n, m);
    }
}

 

Kattis - mixedfractions

标签:str   tor   msu   math   -o   body   data   分数   ber   

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!