| ||||||||||
| 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 | |||||||||
大哥哥们帮忙看下吧!为什么总是run time error#include<iostream.h>
#include<string.h>
#include<stdio.h>
#define N 10000
const int MaxSize = 500;
typedef struct{
int f[MaxSize];
int l;
}FType;
FType fib[N];
typedef struct{
int len;
int n[MaxSize];
}NType;
NType a1, b1;
int lt[MaxSize] = {0};
char a[MaxSize] = {'0'}, b[MaxSize] = {'0'};
void cal_fib();
void read_data();
void output(int a[]);
int cmp(FType &a, NType &b, int n);
void clean();
int main()
{
int n1 = 1, num = 0, t, i;
cal_fib();
while( 1 ){
n1 = 1; num = 0;
clean();
read_data();
if( a[0] == '0' && b[0] == '0') break;
while( 1 ){
t = cmp(fib[n1], a1, n1);
if( t < 0 ){
n1++;
}
else break;
}
while( cmp(fib[n1], b1, n1) <= 0 ){ n1++; num++; }
cout << num <<endl;
}
return 0;
}
void cal_fib()
{
int i , j, flag = 0;
lt[1] = 1;
for(i = 1; i < N; i++)
for( j = 0; j < MaxSize; j++)
fib[i].f[j] = 0;
fib[0].f[MaxSize - 1] = 1; fib[0].l = 1;
fib[1].f[MaxSize - 1] = 1; fib[1].l= 1;
for( i = 2; i<N; i++){
fib[i].l = fib[i - 1].l;
flag = 0;
for(j = MaxSize - 1; fib[i - 1].l >0 ; j--, fib[i - 1].l--){
fib[i].f[j] += ( fib[i - 1].f[j] + fib[i - 2].f[j] );
if(fib[i].f[j] >= 10){
fib[i].f[j - 1] += fib[i].f[j]/10;
fib[i].f[j] %= 10;
if( fib[i - 1].l == 1) flag = 1;
}
}
if(flag == 1) fib[i].l += 1;
lt[i] = fib[i].l;
}
}
int cmp(FType& a, NType& b, int n)
{
int i, j;
a.l = lt[n];
//cout <<" a.l=" <<a.l<<' ';
if(a.l > b.len ){
//cout << a.l <<' '<< b.len<<' ';
//cout << "f > a" <<' ';
return 1;
}
else if(a.l < b.len ){
return -1;
}
else{
for(i = MaxSize - a.l ; i < MaxSize; i++){
if(a.f[i] > b.n[i]) return 1;
else if (a.f[i] < b.n[i]) return -1;
}
}
return 0;
}
void clean()
{
int i;
for(i = 0; i < MaxSize; i++){
a[i] = '0'; b[i] = '0';
a1.n[i] = 0; b1.n[i] = 0;
}
}
void read_data()
{
int i, j, length;
cin >> a; length = strlen(a);
for(i = 0; i < length; i++) a1.n[MaxSize - length + i] = a[i] - '0';
a1.len = length;
cin >> b; length = strlen(b);
for(j = 0; j < length; j++) b1.n[MaxSize - length + j] = b[j] - '0';
b1.len = length;
}
void output(int a[])
{
int bit = 0;
for(; !a[bit]; bit++)
;
for(; bit < MaxSize; bit++) cout << a[bit];
cout<<endl;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator