LUCKY STRING(微软校招)

题目描述
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.
示例1
输入
复制
aabcd
输出
复制
a
aa
aab
aabc
ab
abc
b
bc
bcd
c
cd
d
题意:若一个串的某个子串中元素集合的个数是一个斐波那契数,则它就是幸运串,以字典序输出一个串中的所有幸运串。
思路:数据温暖,set + 暴力 + 预处理数值小于26的斐波那契表。

#include<bits/stdc++.h>
  using namespace std;
   set<int> jj;
    void init()
    {
         vector<int> a;
           a.push_back(1);
             a.push_back(1);
               jj.insert(1);
          int i = 2;
        while(a[i-1] + a[i-2] <= 26)
        {
              int doll = a[i-1] + a[i-2];
                 jj.insert(doll);
                   a.push_back(doll);
                     ++i;
        }
    }
  int main()
  {
       char s[110];
          set<string> v;
         gets(s);
       init();
      for(int i = 0 ; s[i] ; ++ i)
      {
          string ss = "";
           set<char> SET;
            ss += s[i];
              v.insert(ss);
               SET.insert(s[i]);
            for(int j = i + 1 ; s[j] ; ++ j)
            {
                  ss += s[j];
                    SET.insert(s[j]);
                   if(jj.count(SET.size()))v.insert(ss);
            }
      }
     set<string> :: iterator it = v.begin();
         while(it != v.end())
         {
              cout << *it << endl;
              it++;
         }
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值