A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.
输入
A string consisting no more than 100 lower case letters.
输出
Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.
aabcd样例输出
a aa aab aabc ab abc b bc bcd c cd d 题意:给定一个字符串,在他所有连续的子串中,按字典序输出满足子串中不同字母的个数为菲波那切数的子串,注意相同的子串只输出一次。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
using namespace std;
typedef long long ll;
int main()
{
string s,ss;
int len,i,j,f[15],l,k,a[26],cnt;
set<string>se;
set<string>::iterator it;
f[0]=0;
f[1]=1;
f[2]=1;
for(i=3;i<=9;i++)
{
f[i]=f[i-1]+f[i-2];
}
cin>>s;
len=s.length();
for(i=0;i<len;i++)
{
for(j=1;i+j<=len;j++)
{
ss=s.substr(i,j);
l=ss.length();
memset(a,0,sizeof(a));
for(k=0;k<l;k++)
a[ss[k]-'a']=1;
cnt=0;
for(k=0;k<26;k++)
{
if(a[k])
cnt++;
}
for(k=0;k<10;k++)
{
if(f[k]==cnt)
{
se.insert(ss);
break;
}
}
}
}
for(it=se.begin();it!=se.end();it++)
cout<<*it<<endl;
}
题目不难就是题意理解一开始理解骗了wa好几次