Files
python/LuoGu/RuMen/P1482.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

22 lines
675 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}