0

下面的代码段是接受输入t(测试用例的数量)和学生人数n[w]和一个数字g[w]。那么它应该将学生的身高作为输入并将其存储在stu最大大小MAXV为. 的数组中100。但是这个循环永远持续下去。这可能有什么问题?

int t;
cin>>t;
std::vector<int> n(t);
std::vector<int> g(t);
int m =0;
int stu[MAXV];
for(int w=0;w<t;t++)
{
    cin>>n[w]>>g[w];
    for(int i=m;i<n[w] && i < MAXV;i++)
    {
        cin>>stu[i];
       ++m;
   }
} 
4

2 回答 2

2
for(int w=0;w<t;t++)
{

} 

This is an infinite loop. Once t was greater than w, it will be always greater. Incremet w instead of t if You want it to stop.

Correction: it isn't infinite, after overflow, it will stop.

于 2013-05-20T17:52:10.983 回答
2
for(int w=0;w<t;t++) , really ?

I'm sure you meant

for(int w=0;w<t;w++)

Check for other errors too, but this is why you coded an infinite loop

于 2013-05-20T17:53:05.807 回答