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

哈哈哈 过了~~~~ 0ms

Posted by 937207021 at 2011-08-12 16:55:58 on Problem 1350
#include<stdio.h>
typedef int type;
int partition(type *tt,int low,int high);
void Qsort(type *tt,int low,int high);
int main()
{
	int m,j,i,k,tt[100];
	while(scanf("%d",&m),m!=-1)
	{    
		k=0;
	      j=0;
	printf("N=%d:\n",m);
    if(m<1000||m>9999) 
 		k=-1;
	else{ 
	while(m!=0&&m!=6174)
	{    
		tt[0]=m%10;
		tt[1]=(m/10)%10;
		tt[2]=(m/100)%10;
		tt[3]=m/1000;
		Qsort(tt,0,3);
		if(tt[0]==tt[3])
			j++;
		if(m>=1000)
		{
			m=tt[3]*1000+tt[2]*100+tt[1]*10+tt[0]-(tt[0]*1000+tt[1]*100+tt[2]*10+tt[3]);
			if(j==1)
				break;
			printf("%d-%d=%d\n",tt[3]*1000+tt[2]*100+tt[1]*10+tt[0],tt[0]*1000+tt[1]*100+tt[2]*10+tt[3],m);
		}
		else
		{
			m=(tt[3]*1000+tt[2]*100+tt[1]*10+tt[0])/10-(tt[0]*1000+tt[1]*100+tt[2]*10+tt[3]);
			printf("%d-%d=%d\n",(tt[3]*1000+tt[2]*100+tt[1]*10+tt[0])/10,tt[0]*1000+tt[1]*100+tt[2]*10+tt[3],m);
		}
		k++;
	}
	}

	if(k<=1)
		printf("No!!\n");
	else
		printf("Ok!! %d times\n",k);
	}
    return 0;
}
int partition(type *tt,int low,int high)
{
	type pivotkey;
	pivotkey=tt[low];
	while(low<high)
	{
		while(low<high && tt[high]>=pivotkey) high--;
		tt[low]=tt[high];
		while(low<high && tt[low]<=pivotkey) low++;
		tt[high]=tt[low];
	}
	tt[low]=pivotkey;
	return low;
}
void Qsort(type *tt,int low,int high)
{
	int pivot;
	if(low<high)
	{
		pivot=partition(tt,low,high);
		Qsort(tt,low,pivot-1);
		Qsort(tt,pivot+1,high);
	}
}

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