为什么最后一位会多标点

法老王  •  2年前


include

include

using namespace std; int a[1005]; int main() {

int n,k,sum=0;
memset(a,0,sizeof(a));0
cin>>n>>k;
for (int i=1;i<=k;i++)
{
	for (int j=1;j<=n;j++)
	{
		if (j%i==0)
		{
			a[j]=!a[j];
		}
	}
}
for (int j=0;j<=n;j++)
{
	if (a[j])、
	{	
		cout<<j<<",";
	}

}

return 0;

}


评论:

头文件是iostream和cstring


法老王  •  2年前

你直接用#include<bits/stdc++.h>不香吗


202103Clyde  •  2年前

include<bits/stdc++.h>

using namespace std; int main(){ int N,n,s=0,q=0; cin>>N>>n; int a[N+1]; if(n==0){

return 0;

} for(int i=1;i<=N;i++){

a[i]=-1; 

} for(int i=2;i<=n;i++){ for(int j=1;j<=N;j++){

	if(j%i==0) a[j]*=-1;
}	

} for(int i=1;i<=N;i++){

if(a[i]==-1){
	if(q==0) 	{
		cout<<i;
		q=1;	
	}
	else{
		cout<<","<<i;	
	}		
}

}

return 0;

}


太阳系地球中国江苏南通czq  •  2年前