You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
654 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;//mn为输入的两个“/”
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;
}