Fibnacci string

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 }

转载于:https://www.cnblogs.com/hncu1009302xudandan/archive/2012/07/19/2600045.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值