hihocoder Lucky Substrings

lucky substrings

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好几次

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值