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

菜鸟跪求为什么总是OLE

Posted by ly08252436 at 2010-09-02 16:45:56 on Problem 1350
#include<stdio.h>
int max(int n)
{
	int b[10],i=0,j,k,z=0,t;
	while(n)
	{
		b[i]=n%10;
		n=n/10;
		z++;i++;
	}
	for(j=0;j<z;j++)
	{
		for(k=0;k<z-j;k++)
		{
			if(b[k]<b[k+1])
			{t=b[k];b[k]=b[k+1];b[k+1]=t;}
		}
	}
	for(j=0;j<z;j++)
		n=n*10+b[j];
	
	return n;
}

int min(int n)
{
	int b[10],i=0,j,k,z=0,t;
	while(n)
	{
		b[i]=n%10;
		n=n/10;
		z++;i++;
	}
	for(j=0;j<z;j++)
	{
		for(k=0;k<z-j-1;k++)
		{
			if(b[k]>b[k+1])
			{t=b[k];b[k]=b[k+1];b[k+1]=t;}
		}
	}
	for(j=0;j<z;j++)
		n=n*10+b[j];
	
	return n;
}

int main()
{
	int a[100],i=0,c,z;

	while(1)
	{
		z=0;
		scanf("%d",&a[i]);
		if(a[i]==-1)break;
		printf("N=%d:\n",a[i]);
		if(max(a[i])-min(a[i])==0)
		{printf("No!!\n");continue;}
		if(a[i]<1000||a[i]>9999)
		{printf("No!!\n");continue;}
		while(1)
		{
			c=max(a[i])-min(a[i]);
			 printf("%d-%d=%d\n",max(a[i]),min(a[i]),c);
			z++;
			if(c==0||c==6174)
			{
				printf("Ok!! %d times\n",z);break;
			}
			a[i]=c;
		}
		i++;
	}
	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