zhangwch • 18天前
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL gcd(LL x, LL y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
int k;
cin >> k;
while (k--) {
char s[200];
scanf("%s", s);
int a = 0, b = 0, pos;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '/') pos = i;
}
for (int i = 0; i < strlen(s); i++) {
if (i < pos) {
a = a * 10 + s[i] - '0';
} else if (i > pos) {
b = b * 10 + s[i] - '0';
}
}
LL c = gcd(a, b);
cout << a / c << "/" << b / c << "\n";
}
return 0;
}
评论: