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

大牛们帮我看看这个程序,总是wa

Posted by 05568256068 at 2007-08-09 12:10:05 on Problem 1350
#include<cstdio>
#include<algorithm>
using namespace std;
int k;
void change(int m,int *a)
{
   k=0;
   while(m)
   {
    a[k++]=m%10;
    m/=10;        
   }     
}

int main()
{
  int m,a[20],i,j,min,max,an,count,f;
  while(1)
  {
      scanf("%d",&m);
        printf("N=%d:\n",m);
   if(m==-1) break;
   if(m%1111==0||m<1000||m>9999) 
   {
   printf("No!!\n");      
   }
   else 
   {
   count=0;
   an=m;
   while(1)
   {
   change(an,a);
   sort(a,a+k);
   max=min=0;
   for(i=0,j=k-i-1;i<k;i++,j--)
   {
   min=min*10+a[i];
   max=max*10+a[j];
   }
   an=max-min;
   count++;
   printf("%d-%d=%d\n",max,min,an);
   if(an==0||an==6174) break;
   }
   printf("Ok!! %d times\n",count);
   }
  }    
}

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