第三个点和第五个点一直runtime error

#include<iostream>
using namespace std;
char a[10000];
int b[1000];
int c[1000];
int find_min(int a, int b)
{
int c;
if (a < b)
{
a = a + b;
b = a - b;
a = a - b;
}
c = a % b;
while (a % b != 0)
{
a = b;
b = c;
c = a % b;
}
return b;
}
int main()
{
while (cin>>a)
{
if (a[0] == '[') //数字变分数
{
int k = 0;
for (int j = 0; j < int(strlen(a)); j++) //将数字存入数组b中
{
if (a[j] > '0' && a[j] <= '9') { b[k] = a[j] - '0'; k++; }
else
continue;
}
if (k == 1) { cout << b[0] << endl; }//只有一个数字
else
{
int fm = 0;
int fz = 1;
for (int j = k - 2; j >= 0; j--)
{
if (j == k - 2) { fm = b[j + 1]; }
int temp;
int num = b[j];
fz += num * fm;
if (j != 0) //最后一个数字不用再换
{
temp = fm;
fm = fz;
fz = temp;
}
}
int u = find_min(fz, fm);
if (fm == 1) { cout << fz << endl; }
else
{
cout << fz / u << "/" << fm / u << endl;
}

}
}
else//分数变数字
{
int fz = 0;
int fm = 0;
int x = 1;
for (int j = int(strlen(a)) - 1; j >= 0; j--) //提取分子和分母
{
if (a[j] == '/')
{
fm = fz;
fz = 0;
x = 1;
continue;
}

fz += (a[j] - 48) * x;

x = x * 10;
}
//存数字
if (fm == 1) { cout << "[" << fz << "]" << endl; }
else
{
int i = 0;
int temp;
while (fz / fm != fz)
{
c[i] = fz / fm;
i++;
temp = fz % fm;
fz = fm;
fm = temp;
if (fm == 1) { c[i] = fz; }
}
cout << "[" << c[0] << ";";
for (int j = 1; j < i; j++)
{
cout << c[j] << ",";
}
cout << c[i] << "]" << endl;
}

}
}
}

0 条评论

目前还没有评论...

信息

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