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

大牛帮忙

Posted by zks at 2007-08-02 21:16:48 on Problem 1350
  我自己写的程序
样例全过自己做了几个数据也是对的
但是总是wa  
  可以帮我看看不????
#include <stdio.h>
#include <string.h>
void main()
{
	char s1[10]="-1",s2[10]="6174",s3[10]="0";
	char s[10];
	int i,j,sum,wei,key;
	gets(s);
	while(strcmp(s,s1)!=0)
	{
		key=0;
		for(i=0;i<=5;i++)
			if (s[i]=='\0') 
			{ 
				wei=i;
				break;
			}
		
	  if (((s[1]==s[0])&&(s[0]==s[2])&&(s[0]==s[3]))||(wei<4))
	  { 
		  printf("N=%s:\n",s);	  
		  printf("No!!\n");
	  }
		else 
		{   
			 printf("N=%s:\n",s);
			 
		   while((strcmp(s,s2)!=0)&&(strcmp(s,s3)!=0))
		   {    
              for(i=0;i<=4;i++)
				 if(s[i]=='\0') 
				 {
					 wei=i;
					 break;
				 }
			   for(i=0;i<=wei-2;i++)
				   for(j=i+1;j<=wei-1;j++)
				   {
					   if(s[i]<s[j])
					   {
                         s[7]=s[i];
						 s[i]=s[j];
						 s[j]=s[7];
					   }
				   }
             
			if(wei==4)	 sum=(s[0]-s[3])*1000+(s[1]-s[2])*100+(s[2]-s[1])*10+(s[3]-s[0]);
			 else if(wei==3) sum=(s[0]-s[2])*100+(s[2]-s[0]);
			        else if(wei==2) sum=(s[0]-s[1])*10+s[1]-s[0];
					       else sum=0;
				printf("%s-",s);
				key++;
				i=wei-1;
				while(s[i]=='0')
					i--;
				for(j=i;j>=0;j--)
                  printf("%c",s[j]);
                
				  printf("=%d\n",sum);
				if (sum>=0&&sum<=9) 
				{
					s[0]='0'+sum;
					s[1]='\0';
				}
				else if(sum>=10&&sum<=99)
				{ 
					s[0]='0'+sum/10;
					s[1]='0'+sum%10;
					s[2]='\0';

				}
				     else if(sum>=100&&sum<=999)
					 {
						 j=sum/100;
						 s[0]='0'+j;
						 s[1]='0'+(sum-j*100)/10;
						 s[2]='0'+sum%10;
						 s[3]='\0';

					 }
					      else if(sum>=1000&&sum<=9999)
						  {
                         j=sum/1000;
						 s[0]='0'+j;
						 s[1]='0'+(sum-j*1000)/100;
                         s[3]='0'+sum%10;
						 i=sum/10;
						 s[2]='0'+i%10;
						 
						 s[4]='\0'; 
						  }
					 
					 
				

		   }
         printf("Ok!! %d times\n",key);

		}

	 gets(s);
	}

}

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