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 20124233 at 2014-05-12 21:11:14 on Problem 2116
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<string.h> 
#include<math.h>
 using namespace std;
 char a[40],b[40];
 int c[100];
 bool ff=false; 
 int main(){
   	int len1,len2,dex1,dex2,dex3,sum;
    c[0]=1;c[1]=2;
   	for(int i=2;i<100;i++){	
   	   c[i]=c[i-1]+c[i-2];
	   }
    while(scanf("%s%s",a,b)!=EOF){
      dex1=0;
      dex2=0;
      len1=strlen(a);
      len2=strlen(b);
      char vv1[40]="";
	   	   for(int i=0;i<len1;i++)
			 dex1+=c[len1-1-i]*(a[i]-'0');
		   for(int i=0;i<len2;i++)
			 dex2+=c[len2-1-i]*(b[i]-'0');
			 sum=dex1+dex2;ff=false;
	       for(int i=40;i>=0;i--){
	         if(dex1>=c[i]&&dex1<=c[i+1]){dex1-=c[i];strcat(vv1,"1");ff=true;continue;}
             if(ff)strcat(vv1,"0");
       	   }
			 char vv2[40]=""; ff=false;
            for(int i=40;i>=0;i--){
	         if(dex2>=c[i]&&dex2<=c[i+1]){dex2-=c[i];strcat(vv2,"1");ff=true;continue;}
             if(ff)strcat(vv2,"0");
       	   }
       	    dex3=max(strlen(vv1),strlen(vv2)); 
			   cout<<setiosflags(ios::fixed);
	         cout<<setw(3+dex3)<<vv1<<endl; 
		   cout<<'+';cout<<setw(2+dex3)<<vv2<<endl;
		    char vv3[100]="";  ff=false;
		   for(int i=40;i>=0;i--){
	         if(sum>=c[i]&&sum<=c[i+1]){sum-=c[i];strcat(vv3,"1");ff=true;continue;}
             if(ff)strcat(vv3,"0");
       	   }
		   cout<<setw(3);
		         for(int i=0;i<strlen(vv3);i++)cout<<'-';
		         cout<<endl;
		   cout<<setw(3+dex3)<<vv3<<endl<<endl;  
    }
   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