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

这个程序怎么不行了?WHY

Posted by jackch at 2006-08-16 20:37:05 on Problem 2969
#include<iostream>
#include<algorithm>
using namespace std;
bool f(int m,int n);
int main()
{
    char c,str[1000];
    int i,j=0,k=0,l=0,sum=0,s=0,t=0,a[1000];
    cin>>str;
    c=str[j];
    while(c)
    {
            i=c-48;
            if(i==0)s++;
            else if(i==5)t++;
            a[j]=i;
            sum+=i;
            c=str[++j];
     }
    sort(&a[0],&a[j],f); 
    if(s==0&&t==0){cout<<"impossible"<<endl;getchar();return 0;}  
    ////////////////////////////////////////////////////////////////
    if(sum%3!=0)
     {
                if(sum%3==1)
                    {   for(i=j-1;i>=0;i--)
                         {
                           if(a[i]==1||a[i]==4||a[i]==7)
                             {a[i]=10;l=1;break;}
                         }
                         if(l==0) 
                            {  for(i=j-1;i>=0;i--)
                                {
                                  if(a[i]==2||a[i]==5||a[i]==8)
                                     {  
                                          if(k==2) break;
                                          if(k<2)  {a[i]=10;k++;}
                                         
                                     }
                                }
                               if(k!=2){cout<<"impossible"<<endl;getchar();return 0;} 
                           
                          } 
                          
                          
                     }
           ////////////////////////////////////////////////////////////          
               else
                   {  for(i=j-1;i>=0;i--)
                     {
                           if(a[i]==2||a[i]==5||a[i]==8)
                           {a[i]=10;l=1;break;}
                     }
                     if(l==0)     
                          {
                               for(i=j-1;i>=0;i--)
                                 {
                                      if(a[i]==1||a[i]==4||a[i]==7)
                                         {  
                                              if(k==2) break;
                                               if(k<2)  {a[i]=10;k++;}
                                         }
                                 }
                             if(k!=2){cout<<"impossible"<<endl;getchar();return 0;}     
                         }
                        
                        
                   }  
                        
                        
                for(i=0;i<j;i++) 
                    {
                           if(a[i]!=10) cout<<a[i];
                    }
                    getchar();
                  
               
     }
//////////////////////////////////////////////////////////////////////////////////////   
    else
      {
             for(i=0;i<j;i++) 
             cout<<a[i];
      }
      
    getchar();
    return 0;
}

bool f(int m,int n)
 {return m>n;}


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