(一道ACM题)好吧,我承认我C语言没有学多久,帮我看下哪儿错了,谢!

2024-11-26 05:33:06
推荐回答(3个)
回答1:

#include
int main()
{
long a,b,c,d,n;
while(scanf("%d",&a)!=EOF)
{
n=0;
while(a!=123)
{
b=c=d=0;
while(a)
{
if(a%2) c++;
a/=10;
d++;
}
b=d-c;
a=100*b+10*c+d;
n++;
}
printf("%d\n",n);
}
return 0;
}

回答2:

#include

int h(long) ;

int main(void)
{

long n;
int count=0;
clrscr();
printf("Please input the shuju:");
if((scanf("%ld",&n))==EOF)
{
printf("error");
exit(1);
}
while(h(n)!=123)
{
printf("%d\n",h(n));
count++;
n=h(n);

}
printf("%d\n",h(n));
printf("%d",++count) ;
getch();

}
int h(long n)
{

long iz=1,iy;
int b=0,c=0;
while(iz != 0)
{
iz=n/10;
iy=n%10;;
if((iy%2)==0)
b++;
else
c++;
n=iz;

}
return b*100+c*10+b+c;

}

回答3:

我跑的是正确的啊。。。你是那种错误?tl还是pe?