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

ft !output limit exceed?我没觉着错,又有什么特殊情况??

Posted by dexter at 2004-03-13 00:26:26 on Problem 1350
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
char str[5];
char max[5];
char min[5];
int mi;
int temp;
void swap(char *a,char *b)
{
	char temp;
	temp=*a;
	*a=*b;
	*b=temp;
}
void find_max()
{
	int i,j,len;
	strcpy(max,str);
	len=strlen(max);
	for(i=0;i<len-1;i++)
		for(j=1+i;j<len;j++)
			if(max[j]>max[i])
				swap(&max[i],&max[j]);
	max[len]=0;
}
void find_min()
{
	int i,j,len;
	strcpy(min,str);
	len=strlen(min);
	for(i=0;i<len-1;i++)
		for(j=len-1;j>i;j--)
			if(min[j]<min[i])
				swap(&min[i],&min[j]);
	min[len]=0;
	mi=atoi(min);
}
void reverse(char str[])
{
	int i,len;
	char t;
	len=strlen(str);
	for(i=0;i<len/2;i++)
	{
		t=str[i];
		str[i]=str[len-1-i];
		str[len-1-i]=t;
	}
}
void sub()
{
	int i;
	int m,n,tem;
	m=n=0;
	for(i=0;max[i];i++)
		m=(max[i]-'0')+m*10;
	for(i=0;min[i];i++)
		n=(min[i]-'0')+n*10;
	temp=m-n;
	tem=temp;
	for(i=0;tem;i++)
	{
		str[i]=tem%10+'0';
		tem/=10;
	}
	str[i]=0;
	reverse(str);
	printf("%s-%d=%d\n",max,mi,temp);
}
int is_same()
{
	int i,len;
	len=strlen(str);
	for(i=0;i<len-1;i++)
		if(str[i]!=str[i+1])
			return 0;
	return 1;
}
main()
{
	int i;
	gets(str);
	while(strcmp("-1",str))
	{
		i=0;
		printf("N=%s:\n",str);
		if(is_same())
			printf("No!!\n");
		else
		{
			while(1)
			{
				i++;
				find_max();
				find_min();
				sub();
				if(temp==0||temp==6174)
					break;
			}
			printf("Ok!! %d times\n",i);
		}
		gets(str);
	}
}





	

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