首页 > 试题广场 >

LUCKY STRING

[编程题]LUCKY STRING
  • 热度指数:12006 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
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
头像 名字来我身边
发表于 2022-09-02 09:24:30
朴素的思路,用unordered_set去重。代码如下: #include "bits/stdc++.h" using namespace std; int main(){     string s; &n 展开全文
头像 贪吃的迪恩顶呱呱
发表于 2024-05-01 16:56:40
首先理解题意:如字符串aabbcde中,一共有abcde五种字母,而5是斐波那契数,因此这个子串可以被输出;如字符串aabbcdef中,一共有abcdef六种字母,而6不是斐波那契数,因此这个子串不能被输出那么接下来处理好逻辑就行了:先生成给定字符串的所有子串,再分别对每一个子串统计其字母种类数,再 展开全文