|
楼主 |
发表于 2004-5-7 18:20:12
|
显示全部楼层
<FONT size=3>下面是我今天这道题的程序,(稍微改动了点)
#include <iostream.h>
#include <string.h>
#include <stdio.h> //FILE
unsigned __int64 fun( unsigned __int64 i )
{
unsigned __int64 len;
if(i==1)
len=7;
else if(i==2)
len=10;
else {
unsigned __int64 c1Len=10,
c2Len=17,
c3Len=17;
while( i!=3 ) {
i--;
c3Len=c1Len+c2Len;
c1Len=c2Len;
c2Len=c3Len;
}
len=c3Len;
}
return len;
}
int main()
{
FILE * FP;
fp=fopen("b.in","r");
unsigned __int64 c1Len, c2Len,c3Len;
unsigned __int64 n,i,distance;
char c1[] = " T.T^__^";
char c2[] = " T.T^__^T.T";
while( fscanf(fp,"%I64u",&n)!=EOF ) {
if(n<=7)
cout << c1[n] << endl;
else if (n<=10)
cout << c2[n] << endl;
else {
c1Len=10;
c2Len=17;
c3Len=17;
i=3;
while( c3Len<n ){
i++;
c3Len = c1Len+c2Len;
c1Len = c2Len;
c2Len = c3Len;
}
distance = c3Len-n;
while( ! (i==1 || i==2) ) {
if( distance <= fun(i-2) )
i-=2;
else {
distance -= fun(i-2);
i--;
}
}
if(i==1)
cout << c1[7-distance] << endl;
else
cout << c2[10-distance] << endl;
}
}
fclose(fp);
return 0;
}</FONT> |
|