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-18 13:29:46 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,sign=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||sum==0){cout<<"impossible"<<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)
                             {sum-=a[i];a[i]=10;l=1;break;}//由于都是存储个位数,用10取代最后不打印 
                         }
                         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)  {sum-=a[i];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)
                           {sum-=a[i];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)  {sum-=a[i];a[i]=10;k++;}
                                         }
                                 }
                             if(k!=2){cout<<"impossible"<<endl;getchar();return 0;}     
                         }
                        
                        
                   }  
                        
                if(sum==0)  {cout<<"impossible"<<endl;getchar();return 0;}       
                for(i=0;i<j;i++) 
                    {
                           if(a[i]==10) continue;
                           cout<<a[i];
                    }
                    getchar();
                  
               
     }
    /////////////////////////////////////////////////////////////////////////////////   
    else
      {      
             for(i=0;i<j;i++) 
             {
                              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