C++ 如何调试在ide中正常运行但返回分段错误的程序? 使用名称空间std; #包括 职业自行车手 { 公众: int初始速度、acc、超速; }; 无效输入(int n,biker a[]) { 对于(int i=0;i
数组C++ 如何调试在ide中正常运行但返回分段错误的程序? 使用名称空间std; #包括 职业自行车手 { 公众: int初始速度、acc、超速; }; 无效输入(int n,biker a[]) { 对于(int i=0;i,c++,segmentation-fault,C++,Segmentation Fault,数组a最多可以包含100名自行车手。问题陈述指定自行车手的数量最多可以达到10000人 超限数组的末尾将调用一个在判断系统上显示为SEGFULT的错误。要么UB在您的开发系统上显示不同,要么您没有使用足够多的自行车手对其进行测试。解释问题及其答案所需的所有信息,尤其是代码,都应包含在链接会腐烂,对理解问题毫无用处,应该避免。 using namespace std; #include<iostream> class biker { public: int initspee
a
最多可以包含100名自行车手。问题陈述指定自行车手的数量最多可以达到10000人
超限数组的末尾将调用一个在判断系统上显示为SEGFULT的错误。要么UB在您的开发系统上显示不同,要么您没有使用足够多的自行车手对其进行测试。解释问题及其答案所需的所有信息,尤其是代码,都应包含在链接会腐烂,对理解问题毫无用处,应该避免。
using namespace std;
#include<iostream>
class biker
{
public:
int initspeed, acc, speeding;
};
void input(int n, biker a[])
{
for (int i = 0; i < n; i++)
{
//cout<<"Enter the initspeed:"<<"\n";
std::cin >> a[i].initspeed;
//cout<<"Enter the acceleration:"<<"\n";
std::cin >> a[i].acc;
}
}
int main()
{
int n = 0, i = 0, t = 0, max_speed = 0, flag = 0, minimum = 0;
biker a[100];
std::cin >> t;
for (int k = 0; k < t; k++)
{
//cout<<"Enter no of bikers"<<"\n";
std::cin >> n;
//cout<<"enter the max track speed"<<"\n";
std::cin >> max_speed;
//cout<<"Enter the min niker speed"<<"\n";
std::cin >> minimum;
input(n, a);
int j = 1, x = 0;
while (flag < 500)
{
int sum = 0;
for (i = 0; i < n; i++)
{
int prod = 0;
prod = a[i].acc * j;
x = a[i].initspeed + prod;
// cout<<"VAL"<<x<<"\n";
if (x >= minimum)
{
//cout<<"It is greater than minimum";
sum = sum + a[i].initspeed + prod;
//cout<<sum<<"\n";
}
}
if (sum >= max_speed)
{
//cout<<"MAXIMUM ACHIEVED\n";
x = sum;
break;
}
j++;
flag++;
}
//cout<<x<<"\n";
std::cout << j;
}
return 0;
}