当前位置:网站首页>[PTA] 7-24 minimum fraction (15 points)
[PTA] 7-24 minimum fraction (15 points)
2022-07-25 22:52:00 【Panzer_ Jack】
The score can be expressed as molecular / The denominator In the form of . Write a program , Ask the user to enter a score , Then it is reduced to the simplest fraction . The simplest fraction means that the numerator and denominator have no reducible components . Such as 6/12 Can be roughly divided into 1/2. When the numerator is greater than the denominator , It doesn't need to be expressed as an integer and a fraction , namely 11/8 still 11/8; And when the numerator and denominator are equal , Still expressed as 1/1 The fractional form of .
Input format :
Input gives a score in one line , Use a slash between the numerator and denominator / Separate , Such as :12/34 Express 34 Divided 12. Both numerator and denominator are positive integers ( It doesn't contain 0, If you don't know the definition of positive integers ).
Tips :
- about C Language , stay
scanfAdd... To the format string of/, Give WayscanfTo handle this slash . - about Python Language , use
a,b=map(int, input().split('/'))This code handles the slash .
Output format :
Output the simplest fraction corresponding to this score in one line , The format is the same as that entered , using molecular / The denominator The fraction is expressed in the form of . Such as 5/6 Express 6 Divided 5.
sample input :
66/120
sample output :
11/20#include <stdio.h>
int main(void)
{
int a, b, i, t, j;
scanf("%d/%d", &a, &b);
if (a>b)
{
t = a;
}
else
{
t = b;
}
for (j=1; j<=t; j++)
{
for (i=1; i<=t; i++)
{
if (a%i==0 && b%i==0)
{
a /= i;
b /= i;
}
}
}
printf("%d/%d", a, b);
}
边栏推荐
- 单元测试,写起来到底有多痛?
- The difference between "rewrite" and "overload"
- 3 lexical analysis
- [literature reading] - HRL -[hrl with universal policies for multi step robotic control]
- Session and cookie, token and storage
- 【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法
- QT的Tree View Model示例
- The fourth experiment nat
- Structure principle of micro ball vibration switch with chip
- Qtreewidget control of QT
猜你喜欢

技术美术百人计划学习笔记(2)--向量
![[training Day11] Nescafe [greed]](/img/4f/c9c7ae8a7b09ee58dd0fdbc55baf72.png)
[training Day11] Nescafe [greed]

Deploy flash based websites using Google cloud

Dom and events

Recyclerview computehorizontalscrollextend computehorizontalscrollrange computehorizontalscroll for calculating the sliding distance
![[training Day12] x equation [high precision] [mathematics]](/img/4f/51d902e925f9ec60da46d161ed4d17.png)
[training Day12] x equation [high precision] [mathematics]

We media people must have four material websites, and don't worry about finding materials anymore

CMU AI PhD 第一年总结

面试题 17.11. 单词距离 ●●

Websocket summary
随机推荐
[tensorflow] 关于 seed
Ip--- ia review
DOM event object
【PMP学习笔记】第1章 PMP体系引论
【集训DAY11】Calc【数学】
[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]
Opencv compile and call GPU version
The fourth experiment nat
单元测试,写起来到底有多痛?
PE format: analyze and implement IATHOOK
汇编语言与微机原理实验一、实验二、实验三:分支程序设计/循环程序设计/子程序设计
How painful is it to write unit tests?
ECMA 262 12 Lexical Grammer
Today, I sorted out some problems about high collapse
面试题 17.11. 单词距离 ●●
Von Neumann architecture
[training day13] out race [mathematics] [dynamic planning]
[training day13] travel [violence] [dynamic planning]
Express framework
Box model (2)