hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重

#1152 : Lucky Substrings
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
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

题目分析:给你一个字符串,找出这个串的连续子串,但是我们不全部输出,只输出那些子串中不同字母数刚好也是斐波那契数的

子串。举例:子串:a(斐波那契数=1)合法;  aabcd(有4个不同字母,4不是斐波那契数) 不合法,不输出。

算法实现:用c++的strsub()函数,一次划分出每次子串,判断每个子串是否合法。如果合法,将其插入到STL set集合里面,这

样做也省去了去除重复子串的麻烦,输出集合set里面的内容时,是按顺序已经排好的。

代码:

  

 

posted @   我喜欢旅行  阅读(900)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示