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 jackch at 2006-08-16 22:16:01 on Problem 2969
#include<iostream>
#include<algorithm>
using namespace std;
bool f(int m,int n){return m>n;};
int main()
{
    char c,str[1000];
    int i,j=0,k=0,l=0,o=1,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];
     }
     
    if(j==1&&a[0]%3!=0){cout<<"impossible"<<endl;getchar();return 0;}  
       else if(j==1&&a[0]%3==0){cout<<a[0]<<endl;getchar();return 0;}
    
    if(s==0&&t==0){cout<<"impossible"<<endl;getchar();return 0;} 
    sort(&a[0],&a[j],f);
    if(s==0&&t!=0)
         { for(i=0;i<j;i++)
            {  if(a[i]==5)
               {a[i]=0;break;}
            }
             sort(&a[0],&a[j],f);a[j-1]=5;
         }
      else ;
     
    ////////////////////////////////////////////////////////////////
    if(sum%3!=0)
     {
                if(sum%3==1)
                    {   for(i=j-2;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-2;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-2;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-2;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) continue;
                           if(0!=0&&a[i]==0);
                           else {o=0;cout<<a[i];}
                    }
                    getchar();
                  
               
     }
//////////////////////////////////////////////////////////////////////////////////////   
    else
      {      
             for(i=0;i<j;i++) 
             {
                              if(0!=0&&a[i]==0);
                              else {o=0;cout<<a[i];}
             }
             getchar();
      }
      
    getchar();
    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