gpt4 book ai didi

c++ - 程序没有进入 FOR 循环

转载 作者:行者123 更新时间:2023-11-27 23:04:26 25 4
gpt4 key购买 nike

我不知道为什么,但程序没有进入 FOR 循环。我对编程完全陌生,所以请避免出现任何错误。非常感谢帮助。

这个问题来自编码网站之一::

You are given a list of N people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-people team can know. And also find out how many teams can know that maximum number of topics?

Input Format

The first line contains two integers N and M separated by a single space, where N represents the number of people, and M represents the number of topics. N lines follow. Each line contains a binary string of length M. In this string, 1 indicates that the ith person knows a particular topic, and 0 indicates that the ith person does not know the topic.

Output Format

On the first line, print the maximum number of topics a 2-people team can know. On the second line, print the number of teams that can know the maximum number of topics.

Constraints

2 ≤ N ≤ 500 

1 ≤ M ≤ 500

Sample Input

4 5
10101
11100
11010
00101

Sample Output

5
2

这是我的代码::

#include<iostream>

using namespace std;

int main(){
int N,M;
cin>>N>>M;

if(N>=2 && N<=500 && M>=1 && M<=500){
int x= (N*(N-1))/2;
int i,j,k;
int Topic[x];
for(i=0;i<x;i++){
Topic[i]=0;
}
int y= N*M;
int a;
char Array[y];
while(N--){
for(i=0;i<M;i++){
cin>>Array[a];
a++;
}
}
int count;
int d=0;
int l=N-1;

// This FOR LOOP ..

**for(int p=0;p<l;p++){
for(int q=p+1;q<N;q++){
count=0;
for(k=0;k<M;k++){
int temp=k+(q*M);
int temp1=k+(p*M);
if(Array[temp]+Array[temp1]!=0){
count+=1;
}
}
Topic[d]=count;
d++;
}
}**
int max=Topic[0];
int counter=0;
for(i=0;i<x;i++){
if(max>Topic[i]){
max=Topic[i];
counter=1;
}
else if(Topic[i+1]=Topic[i]){
counter+=1;
}
}

cout<<max<<endl;
cout<<counter;

}

return 0;
}

最佳答案

你有一个循环计数 N下降到 0 :

while (N--) {
// ...
}

然后你设置lN - 1 ,也就是说 -1 :

int l = N - 1;

然后是你的for循环想要在 p < l 时运行. p最初是 0 , l最初是 -1 ,所以循环永远不会运行:

for ( int p = 0; p < l; p++ ) {
// ...
}

关于c++ - 程序没有进入 FOR 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24598491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com