Kattis - mixedfractions

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,231−1][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 1 Sample 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);
    }
}
时间: 2024-10-16 00:55:00

Kattis - mixedfractions的相关文章

Kattis - Association for Computing Machinery

Association for Computing Machinery ACM (Association for Computing Machinery) organizes the International Collegiate Programming Contest (ICPC) worldwide every year. In the ICPC, a team of three students is presented with a problem set that contains 

Kattis downtime

链接:https://open.kattis.com/problems/downtime 题意:n个要解决的进程,每个服务器可以解决k个进程,每个进程花费1000MS,给出n个进程的开始时间,问最少要几个服务器 思路:我们可以求出每个进程的区间,然后看我们可以不重叠的解决多少个进程 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct node{ 5 int x; 6 int y; 7 }a[200005]; 8 bool cm

City Destruction Kattis - city dp

/** 题目:City Destruction Kattis - city 链接:https://vjudge.net/problem/Kattis-city 题意:有n个怪兽,排成一行.每个怪兽有一个生命值和一个爆炸值.每次可以选择一个怪兽攻击早造成d伤害. 如果生命值<=0:那么怪兽i死亡并且爆炸.i+1,i-1第怪兽都会受到 第i个怪兽的爆炸值伤害.如果第i-1被第i炸死,第i-1怪兽不会继续炸别人. 不会传递.也就是只有攻击者攻击致死的怪兽才会对i-1,i+1造成爆炸值伤害. 求最少攻击

Installing Apps Kattis - installingapps (贪心 + 背包)

Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her friends suggested a long list of applications (more commonly known as “apps”) that she should install on the phone. Sandra immediately started installing

Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些连续子串中的非连续子串中包含t的有多少个. 具体思路:我们枚举s的每一个位置,然后判断一下s的包含t的非连续子串中到达那个位置,然后这个字符串两边的长度相乘就是当前位置开始,满足条件的字符位置.然后我们在找从上一次找到首字母位置下一个开始, 继续往下找就可以了. AC代码: 1 #include<b

A - Piece of Cake Kattis - pieceofcake (数学)

题目链接: A - Piece of Cake Kattis - pieceofcake 题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面积的期望. 具体思路:我们肯定不能硬跑每一个k边形,肯定会超时.我们以每个点作为起点,从这个点开始,形成的面积的期望是多少,然后遍历每一个点,这样算出来的会有重复,最后除以2就可以了. 然后算面积的时候,我们分开算.一个多边形的面积等于每个点按照顺时针或者是逆时针两个点之间的叉积. 求组合数的时候,

Kattis - hoppers Hoppers(判奇环)

题目传送门:Kattis - hoppers  Hoppers 题目大意: 你是一个黑客,现在你发明了一种感染病毒,这种感染病毒能够感染到与该主机相隔一个点的主机. 存在一个无向图,每个点代表一台主机,每条无向边表示两台主机相连,现在你有个计划是通过感 染一个电脑让所有电脑感染,你可以为两条电脑之间加边,需要你求出最少加多少条边能够完成计划 分析: 我们能够发现奇数环中任何一个点被感染都能够使奇数环中所有的点感染.因此我们可以利用该性质. 为了满足条件(感染一个点使所有点被感染)存在几种情况:

G - Non-Prime Factors Kattis - nonprimefactors (筛1-n内的当前数中非素数的个数)

题目链接: G - Non-Prime Factors  Kattis - nonprimefactors 题目大意:给你一个数n,然后问你n的因子中非素数的个数. 具体思路:埃筛,把每一个数的因子直接算出来就好了. AC代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 2e6 + 100; 4 int vis[maxn]; 5 int sto[maxn]; 6 void init() 7 { 8 f

kattis Curious Cupid (莫队算法)

Curious Cupid There are K different languages in the world. Each person speaks one and only one language. There are exactly N single men and N single women. Cupid, the god of love, wants to match every single man to a single woman, and vice versa. Ev