本帖最后由 永恒的蓝色梦想 于 2020-5-21 12:57 编辑
如果满意,不妨给个最佳#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef long long ll;
ll gcd(ll a, ll b) {
ll t = 0;
while (b) {
t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
long long a, b, t, temp;
for (;;) {
scanf("%lld", &a);
temp = getchar();
if (temp == '\n') {
printf("[%lld]\n", a);
}
else {
if (temp == '/') {
scanf("%lld", &b);
}
else if (temp == '.') {
for (b = 1; (temp = getchar()) != '\n'; b *= 10) {
a = temp - 48 + a * 10;
}
}
if (a) {
t = gcd(a, b);
if (t == b) {
printf("[%lld]\n", a / t);
}
else {
printf("[%lld/%lld]\n", a / t, b / t);
}
}
else {
puts("[0]");
}
}
}
return 0;
}
|