博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces666A
阅读量:4671 次
发布时间:2019-06-09

本文共 3475 字,大约阅读时间需要 11 分钟。

Reberland Linguistics

 

First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.

For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).

Here is one exercise that you have found in your task list. You are given the word s. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.

Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.

Let's look at the example: the word abacabaca is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {

aca, ba, ca}.

Input

The only line contains a string s (5 ≤ |s| ≤ 104) consisting of lowercase English letters.

Output

On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes.

Print suffixes in lexicographical (alphabetical) order.

Examples

Input
abacabaca
Output
3 aca ba ca
Input
abaca
Output
0

Note

The first test was analysed in the problem statement.

In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.

 

sol:像个dp一样,略微有点阿八。需要熟练掌握字符串的STL

从后往前推,每次判断一段区间是否会有重复,然后向前转移

/*题目大意:一个单词由长度不少于5的词根和长度为2或3的若干个后缀组成,并且两个相邻的后缀不能一样,给定一个单词,问这个单词总共可以有多少个后缀*/#include 
using namespace std;typedef int ll;inline ll read(){ ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s);}#define R(x) x=read()inline void write(ll x){ if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return;}#define W(x) write(x),putchar(' ')#define Wl(x) write(x),putchar('\n')const int N=10005;int n;string S;bool dp[N];set
Ans;set
::iterator it;int main(){ int i; string t; cin>>S; n=S.size(); if(n<=6) return puts("0"),0; dp[n]=1; for(i=n-2;i>=5;i--) { if(dp[i+2]) { t=S.substr(i,2); if(Ans.find(t)==Ans.end()||dp[i+5]) {Ans.insert(t); dp[i]=1;} } if((i!=n-2)&&dp[i+3]) { t=S.substr(i,3); if(Ans.find(t)==Ans.end()||dp[i+5]) {Ans.insert(t); dp[i]=1;} } } Wl((int)(Ans.size())); for(it=Ans.begin();it!=Ans.end();++it) { cout<<*it<
View Code

 

转载于:https://www.cnblogs.com/gaojunonly1/p/11141182.html

你可能感兴趣的文章
ES之各种运算符,for、while、do while 、switch case循环
查看>>
Twisted
查看>>
python-day34--进程补充
查看>>
POJ 1001 Exponentiation
查看>>
Redhat之package管理--学点 YUM和RPM
查看>>
使用Bochs调试Linux kernel 随笔 -- 准备
查看>>
Ajax 密码验证
查看>>
idea的项目结构
查看>>
stl pair
查看>>
python路径相关小问题
查看>>
老李分享:持续集成学好jenkins之Git和Maven配置
查看>>
Android深度探索-卷1第二章心得体会
查看>>
linux中cat、more、less命令区别详解
查看>>
java读写文件总结
查看>>
阿里题目:明星群众问题
查看>>
为什么SQL用UPDATE语句更新时更新行数会多3行有触发器有触发器有触发器有触发器有触发器有触发器...
查看>>
关于hist
查看>>
Xtrareport 交叉报表
查看>>
谭浩强C语言第四版第九章课后习题7--9题(建立,输出,删除,插入链表处理)...
查看>>
20145101 《Java程序设计》第7周学习总结
查看>>