第四个老是错误,,

#include <iostream>
#include <string>
#include <string.h>
using namespace std;
long a[1000];
void aha1(int x, int y, int t,bool flag)
{
for (int i = t; i >= 1; i--)
{
long c = x;
x = y;
y = c;
x = x + y*a[i];
}
cout << x;
if (y != 1)
cout <<'/'<< y << endl;
if (!flag&&y==1)
cout << endl;
return;
}
void aha2(int x, int y)
{
long k;
k = x / y;
if (x%y == 0)
cout << '['<<k<<']' << endl;
else
{
cout << '[' << k << ';';
x = x - k*y;
while (x != 0)
{
int c = x;
x = y;
y = c;
k = x / y;
x = x - k*y;
if (x == 0)
{
cout << k;
}
else
cout << k << ',';
}
cout << ']' << endl;
}
}
int main() {
string x;
bool flag=false;
while (cin>>x)
{
memset(a, 0, sizeof(a));
if (x[0] == '[')
{
int t = 1, q = 1;
while (x[q] != ']')
{
if (x[q] >= '0'&&x[q] <= '9')
{
a[t] = a[t] * 10 + x[q] - '0';
}
else
t++;
q++;
}
if (x[t] == ';')
{
t--;
flag = true;
cout << '[';
aha1(a[t], 1, t - 1,flag);
cout << ']';
cout << endl;
flag = false;
}
else
aha1(a[t], 1, t - 1,flag);
}
else
{
int t = 1, q = 0;
while (x[q] != '\n'&&x[q] != EOF&&x[q] != '\0')
{
if (x[q] >= '0'&&x[q] <= '9')
{
a[t] = a[t] * 10 + x[q] - '0';
}
else
t++;
q++;
}
int m = a[1], n = a[2];
aha2(m, n);
}
}
return 0;
}

1 条评论

  • 1

信息

ID
1696
难度
7
分类
其他 | 数学模拟 点击显示
标签
递交数
5158
已通过
1140
通过率
22%
被复制
3
上传者