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

试过一些边缘性的数么?1 8或者1 1e100或者8 8之类的

Posted by frkstyc at 2005-04-24 03:23:44 on Problem 2413
In Reply To:为什么这道简单题都不停的wa,有什么陷阱?太受打击了 Posted by:cpp051300448324 at 2005-04-24 03:08:19
> #include<iostream>
> #include<cstring>
> 
> #define max(a,b) (a>b?a:b)
> using namespace std;
> 
> short str[600][1000]={0};
> 
> void plus_(short* s1,short* s2,short*res){
>     int len=max(s1[0],s2[0]);
>     int i;
>     for(i=1;i<=len;i++){
>         res[i]+=(s1[i]+s2[i])%10;
>         res[i+1]+=(s1[i]+s2[i])/10;
>     }
>     if(res[len+1]!=0)len++;
>     res[0]=len;
> }
> 
> int compare(short*s1,short*s2){
>     int i;
>     if(s1[0]<s2[0])return -1;
>     else if(s1[0]>s2[0])return 1;
>     int len=s1[0];
>     for(i=len;i>=1;i--){
>         if(s1[i]>s2[i])return 1;
>         else if(s1[i]<s2[i])return -1;
>     } 
>     return 0;
> }
> 
> void ini(){
>     str[1][0]=1;
>     str[1][1]=1;
>     str[2][0]=1;
>     str[2][1]=2;
>     int i=3;
>     while(i<600){
>         plus_(str[i-1],str[i-2],str[i]);
>         /* for(int j=str[i][0];j>=1;j--){
>             cout<<str[i][j];
>         }
>         cout<<endl; */ 
>         i++;
>     }
> }        
>                     
>     
>         
>     
> 
> int main(){
>     int i,j;
>     ini();
>     short s1[1000],s2[1000];
>     char _s1[1000],_s2[1000];
>     short end[1000]={1};
>     int len_1,len_2;
>     //scanf("%s %s",_s1,_s2);
>     cin>>_s1>>_s2;
>     len_1=strlen(_s1);
>     len_2=strlen(_s2);
>     s1[0]=len_1;
>     for(i=1;i<=len_1;i++){
>         s1[i]=_s1[len_1-i]-'0';
>     }    
>     s2[0]=len_2;
>     for(i=1;i<=len_2;i++){
>         s2[i]=_s2[len_2-i]-'0';
>     }    
>     while(compare(s1,end)!=0||compare(s2,end)!=0){
>         int num_1,num_2;
>         int n=1;
>         while(compare(str[n],s1)<0){
>             n++;
>         }
>         num_1=n-1;
>         if(n>1)n--;
>         while(compare(str[n],s2)<=0){
>             n++;
>         }
>         num_2=n-1;
>         /* for(i=s1[0];i>=1;i--){
>             cout<<s1[i];
>         }
>         cout<<endl;
>         for(i=s2[0];i>=1;i--){
>             cout<<s2[i];
>         }
>         cout<<endl;   */ 
>         //cout<<num_1<<' '<<num_2<<endl;      
>         cout<<num_2-num_1<<endl;
>         //scanf("%s %s",_s1,_s2);
>         cin>>_s1>>_s2;
>         len_1=strlen(_s1);
>         len_2=strlen(_s2);
>         s1[0]=len_1;
>         for(i=1;i<=len_1;i++){
>             s1[i]=_s1[len_1-i]-'0';
>         }    
>         s2[0]=len_2;
>         for(i=1;i<=len_2;i++){
>            s2[i]=_s2[len_2-i]-'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