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 20062507 at 2008-07-22 19:19:28 on Problem 1117
#include<iostream>
#include<algorithm>
using namespace std;
int A[100];
int C[11];
int N=0;
int K=0;
int pow10(int k)
{
    int s=1;
    while(k>0)
    {
              s=s*10;
              k--;
    }
    return s;
}
void pairs_of_integers()
{
     int kk=N;int ii=0;
     while(kk/10!=0)
     {
                   C[ii]=kk%10;
                   kk=kk/10;
                   ii++;
     }
     C[ii]=kk;
     if(N%2==0)
     {
               for(int k=1;k<=ii;k++)
               {
                       int b=0,c=0; 
                       int high=0,low=0;
                       for(int i=0;i<k;i++)
                       {low+=C[i]*pow10(i);}
                       for(int i=k+1;i<=ii;i++)
                       {high+=C[i]*pow10(i-k-1);}
                       for(int t0=0;t0<=1;t0++)
                       {
                               for(int t1=0;t1<=1;t1++)
                               {  
                                       c=(low+t0*pow10(k))/2;
                                       b=high-t1;
                                       if(b>=0)
                                       {
                                       int x=C[k]+t1*10-b-t0;
                                       if(x>=0&&x<=9)
                                       {
                                                      if(k==ii&&x==0)
                                                         break;
                                                     int a;
                                                     a=b*pow10(k+1)+x*pow10(k)+c;
                                                     A[K]=a;
                                                     K++;
                                       }
                                       }
                               }
                       }
               }
     }
    for(int x=0;x<=9;x++)
     {
             int t=(N-x)%11;
             if(t==0)
             {
                   int a=x+10*(N-x)/11;
                   A[K]=a;
                   K++;
             }
     }
}
void output()
{
     sort(A,A+K);
     int n=K;
     for(int i=0;i<K;i++)
     {
             if(A[i]==A[i+1])
             {
                             A[i]=0;
                              n--;
             }
     }
     cout<<n<<endl;
     for(int i=0;i<K;i++) 
     {
             if(A[i]!=0)
             {
             cout<<A[i]<<'+';
            int b=N-A[i];
             int ak=(int)A[i],bk=(int)b;
             int al=1,bl=1;
             while(ak/10!=0)
             {
                            ak=ak/10;
                            al++;
             }
             while(bk/10!=0)
             {
                            bk=bk/10;
                            bl++;
             }
             int j=al-bl;
             while(j>1)
             {
                       cout<<'0';
                       j--;
             }
             cout<<b<<'='<<N<<endl;
            }
     }
}                  
int main()
{
    while( cin>>N)
    {
    pairs_of_integers();
    output();
    memset(A,false,sizeof(A));
    memset(C,false,sizeof(C));
    K=0;
    N=0;
    }
   // system("pause");
    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