疑惑求解
查看原帖
疑惑求解
1267232
limitlessly楼主2024/10/16 21:25

为什么两个输出完全相同且正确的程序的其中一个会WAWA(20pts20pts),可另一个程序会ACAC?

WAWA codecode:

#include<bits/stdc++.h>
using namespace std;
int a[10000],n,idx;
int main(){
	scanf("%d",&n);
	a[0]=n;
	while(a[idx-1]!=1)a[++idx]=a[idx-1]%2==0?a[idx-1]/2:a[idx-1]*3+1;
	while(idx--)printf("%d ",a[idx]);
	return 0;
}

AC codeAC\ code:

#include<bits/stdc++.h>
using namespace std;
int a[10000],n,idx;
int main(){
	scanf("%d",&n);
	a[0]=n;
	while(a[idx]!=1){
		idx++;
		if(a[idx-1]%2==0)a[idx]=a[idx-1]/2;
		else a[idx]=a[idx-1]*3+1;
	}
	for(int i=idx;i>=0;i--)printf("%d ",a[i]);
	return 0;
}

求解答

2024/10/16 21:25
加载中...