| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪里错了??不明白啊顺序查找都错?求大牛看看哪。。#include<iostream>
#include<string>
#include<time.h>
using namespace std;
#define MAX 300
#define MAX_L 1000
struct fun
{
int num[MAX];
}data[MAX_L];
int cmp(int a[],int b[]) //高精度比较法,a>b返回1 相等返回0 a<b返回 -1
{
int t_la = 0,t_lb = 0,i;
for( i = 0; i < MAX; i++ )
{
if( a[i] != 0 )
break;
}
t_la = MAX - i;
for( i = 0; i < MAX; i++ )
{
if( a[i] != 0 )
break;
}
t_lb = MAX - i;
if( t_la > t_lb )
return 1;
else if( t_la < t_lb )
return -1;
else
{
for( i = MAX - t_la; i < MAX; i++ )
if( a[i] > b[i] )
return 1;
else if( a[i]<b[i] )
return -1;
return 0;
}
}
void add(int a[],int b[],int ans[]) //高精度加法
{
int carry = 0,temp[MAX] = {0},data;
for( int i = MAX - 1; i >= 0; i-- )
{
data = a[i] + b[i] + carry;
if( data >= 0 )
{
temp[i] = data % 10;
carry = data / 10;
}
else
{
temp[i] = data;
carry = 0;
}
}
memset(ans,0,sizeof(ans));
for( int i = 0; i < MAX; i++ )
ans[i] = temp[i];
}
void change(int num[],char temp[]) //高精度转换
{
for( int i = MAX - 1,j = strlen(temp) - 1; i >= 0 && j >= 0; i--, j-- )
num[i] = temp[j] - '0';
}
int main()
{
// clock_t begin,end;
// begin = clock();
// freopen("E://input.txt","r",stdin);
char a[MAX] = {'\0'},b[MAX] = {'\0'};
int num1[MAX] = {0},num2[MAX] = {0},count;
memset(data[0].num,0,sizeof(data[0].num));
memset(data[1].num,0,sizeof(data[0].num));
data[0].num[MAX-1] = 1;
data[1].num[MAX-1] = 2;
for( int i = 2; i < MAX_L; i++ )
add(data[i-1].num,data[i-2].num,data[i].num);
while( scanf("%s%s",a,b) != EOF )
{
count = 0;
if( !strcmp(a,"0") && !strcmp(b,"0") )
break;
change(num1,a);
change(num2,b);
for( int i = 0; i < MAX_L; i++ )
{
if( cmp(data[i].num,num1) >= 0 && cmp(data[i].num,num2) <= 0 )
count++;
}
cout<<count<<endl;
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
}
// end = clock();
// cout<<end - begin<<"MS"<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator