呃呃呃,这里是代码,上面的粘贴错了
#include <stdio.h>
typedef long long ll;
//求最大公约数
ll f1(ll a, ll b) {
ll t = 0;
while (b) {
t = a % b;
a = b;
b = t;
}
return a;
}
int main() {
ll a, b, t, temp;
if(scanf("%lld", &a)==1)
{
//scanf("%lld", &a);
temp = getchar();
if (temp == '\n') {
printf("[%lld]\n", a);
return 0;
}
else {
if (temp == '/') {
if(scanf("%lld", &b)!=1)
return 0;
}
else if (temp == '.') {
for (b = 1; ((temp = getchar()) !='\n'); b *= 10) {
a = temp - 48 + a * 10;//字符串转换为数值
}
}
if (a&&b) {
t = f1(a, b);
if (t == b) {//如果最大公约数是b
printf("[%lld]\n", a / t);
return 0;
}
else {
printf("[%lld/%lld]\n", a / t, b / t);
return 0;
}
}
else {
puts("[0]");
return 0;
}
}
}
}
|