Reberland Linguistics

CodeForces - 666A

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 <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
string S;
bool dp[N];
set<string>Ans;
set<string>::iterator it;
int main()
{
int i;
string t;
cin>>S; n=S.size();
if(n<=) return puts(""),;
dp[n]=;
for(i=n-;i>=;i--)
{
if(dp[i+])
{
t=S.substr(i,);
if(Ans.find(t)==Ans.end()||dp[i+]) {Ans.insert(t); dp[i]=;}
}
if((i!=n-)&&dp[i+])
{
t=S.substr(i,);
if(Ans.find(t)==Ans.end()||dp[i+]) {Ans.insert(t); dp[i]=;}
}
}
Wl((int)(Ans.size()));
for(it=Ans.begin();it!=Ans.end();++it)
{
cout<<*it<<endl;
}
return ;
}
/*
Input
abacabaca
Output
3
aca
ba
ca Input
abaca
Output
0
*/

codeforces666A的更多相关文章

随机推荐

  1. 怎样使用 v-html 指令?

    v-html 可以在目标节点位置内部插入 html 子节点, 跟节点的 .innerHTML 属性类似, 使用方法如下: <!DOCTYPE html> <html lang=&qu ...

  2. python中获取当前位置所在的行号和函数名(转)

    http://www.vimer.cn/2010/12/%E5%9C%A8python%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E4%BD%8D%E7 ...

  3. Myeclipse启动后tomcat空指针异常

    今天早上吃完早餐来公司上班,打开电脑,输入密码,123456.....嗯……,再打开myeclipse,duang...duang...duang....tomcat空指针异常,tmd我这暴脾气昨天还 ...

  4. left join 和 inner join 区别和优化

    关联查询总结,left join 和 inner join 区别和优化 一直以来都没有细细的研究 left join 和 inner join,现在发觉要做优化还真的是要熟悉它们的区别才行. 原谅转载 ...

  5. js之运算符(关系运算符)

    关系运算符用于测试两个值之间的关系,根据关系是否存在而返回true或者是false.关系表达式总是返回一个布尔值. 具有如下8个关系运算符:大于(>),小于(<),小于等于(<=), ...

  6. JavaScript的常用浏览器设置

    用什么浏览器?如果您不告诉我您使用的浏览器,我将告诉您有关JavaScript的常用浏览器设置.~火狐在菜单栏中选择工具->选项->内容以查看启用javascript的选项.Interne ...

  7. Java高并发程序设计学习笔记(九):锁的优化和注意事项

    转自:https://blog.csdn.net/dataiyangu/article/details/87612028 锁优化的思路和方法减少锁持有时间减小锁粒度锁分离锁粗化举个栗子举个栗子锁消除虚 ...

  8. sqoop 安装

    Sqoop是一款开源的工具,主要用于在Hadoop(Hive)与传统的数据库(mysql.postgresql...)间进行数据的传递,可以将一个关系型数据库(例如 : MySQL ,Oracle , ...

  9. JAVA语言程序设计课后习题----第三单元解析(仅供参考)

    1 本题水题,记住要知道输入格式即可 import java.util.Scanner; public class test { public static void main(String[] ar ...

  10. Java实现文本中的关键字高亮,匹配所有长度

    这个方法还不完整,后面想起来再看,直接放代码 public static String getHeightlightWord(String textWord, String key){ StringB ...