'commit'
This commit is contained in:
22
LuoGu/RuMen/P1482.cpp
Normal file
22
LuoGu/RuMen/P1482.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//自定义一个求最大公因数的函数,用来约分(辗转相除法)(这里用到了一个三目运算符)
|
||||
int gcd(int a, int b) {
|
||||
return b == 0 ? a : gcd(b, a % b);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a, b, x, y, s;//s为新分数分子和分母的最大公因数
|
||||
char m, n;//m,n为输入的两个“/”
|
||||
cin >> a >> m >> b;
|
||||
cin >> x >> n >> y;
|
||||
x *= a;
|
||||
y *= b;
|
||||
s = gcd(x, y);//x为新分子,y为新分母,s为最大公因数
|
||||
x /= s;
|
||||
y /= s;//约分
|
||||
cout << y << " " << x;//输出第y列,第x行(顺序不能写反,否则只有20分)
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user