Fibnacci string
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 208, Accepted users: 172
Problem 10805 : No special judgement
Problem description
The Fibnacci string is as follows:
S1=b
S2=a
Sk=Sk-1Sk-2 k>2
We are given a string, is there a Fibnacci string? 

Input
The input will consist of a series of string, one string per line, followed by a line containing only the char ‘0’ that signals the end of the input file and need not to be processed.
You may assume that the length of each string is no more than 1,000,000.


Output
For each string you should output the ‘true’ if the string is a Fibnacci string, or ‘false’ if the string is not a Fibnacci string and with one line of output for each line in input. 

Sample Input
abaab
abaababa
abaababaababa
0
Sample Output
true
true
false
Problem Source
HNU Contest 

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 char a[1000001],b[1000001],c[1000001],s[1000001];
 5 
 6 int main()
 7 {
 8     int len,len1;
 9     while(gets(s)&&strcmp(s,"0")!=0)
10     {
11         len=strlen(s);
12         strcpy(a,"b");
13         strcpy(b,"a");
14         len1=0;
15         if(strcmp(s,b)==0||strcmp(s,a)==0)   printf("true\n");
16         else
17         {
18         for(;len>len1;)
19         {
20             strcpy(c,b);
21             strcat(b,a);        
22             strcpy(a,c);
23             len1=strlen(b);
24         }
25         if(strcmp(s,b)==0)   printf("true\n");
26         else printf("false\n");
27         }
28     }
29    return 0;
30 }
posted on 2012-07-19 21:51  黑色的铅笔  阅读(155)  评论(0编辑  收藏  举报