Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大牛们,怎么会RE?附代码

Posted by benny2008 at 2007-11-18 08:11:36 on Problem 1350
#include"stdio.h"
#include"math.h"
void sort(int array[])
{ int i,j;
  int temp;
	for(i=0;i<3;i++)
	    for(j=0;j<3-i;j++)
			if(array[j]<array[j+1])
			{temp=array[j];
             array[j]=array[j+1];
              array[j+1]=temp;
              }
}


int main()
{int a;
 int array[4];
 int b[10];
 int i,j,k=0,t[4],n,m; 
 int x=0,y=0;
 int w;
 
 while(scanf("%d",&a)&&a!=-1)
 {if(a==0) 
 {printf("N=%d:\n",a);
  printf("No!!\n");
 }
  while(a!=0)
  {  b[k]=a;
     w=0;
	 while(a!=0)
	 {array[w]=a%10;
	  a=a/10;
	  w++;
	 }
	sort(array);
    for(i=0,j=w-1;i<w&&j>=0;i++,j--)
		 a+=array[i]*(int)pow(10,j)-array[j]*(int)pow(10,j);
    if(k==0&&a==0||k==0&&w!=4) 
	{printf("N=%d:\n",b[0]);
     printf("No!!\n");
	 break;
	}
	
	
	k++;
    if(a==6174||a==0)
	{printf("N=%d:\n",b[0]);
    for(i=0;i<k;i++)
	{j=0;
	      while(b[i]!=0)
		  {t[j]=b[i]%10;
	       b[i]=b[i]/10;
	       j++;
		  }
		  sort(t);
	    for(m=0,n=j-1;m<j&&n>=0;m++,n--) 
		{x+=(int)(pow(10,n))*t[m];
		 y+=(int)(pow(10,n))*t[n];
		}
	  printf("%d-%d=%d\n",x,y,x-y);
		x=0;
		y=0;
	}
       printf("Ok!! %d times\n",k);
	break;
	}
			 
 }
  k=0;
 }
 return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator