time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

【题解】



这题的限制是说连续的两个串不能是一样的。

如果中间隔了一个是允许的0 0

设can[i][2]和can[i][3]分别表示从I点能否截取长度为2、长度为3的连续串;

初始化can[len-1][2] = true,can[len-2][3] = true;

转移方式如下

            if (can[i+2][3] || (can[i+2][2] && s.substr(i,2)!=s.substr(i+2,2)))
{
can[i][2]=true;
·····
}
if (can[i+3][2] || (can[i+3][3] && s.substr(i,3)!=s.substr(i+3,3)))
{
can[i][3]=true;
.....
}
//每次截取到一串就加入到vector中。最后把vector用sort排下序;
//顺序输出就好;
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define LL long long using namespace std; const int MAXN = 1e4+10; string s;
vector <string> a;
map <string,int> dic;
bool can[MAXN][5] = {0}; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
cin>>s;
int len = s.size();
string temp;
for (int i = len-2;i>=5;i--)
{
if (i+1==len-1)
{
can[i][2] = true;
temp = s.substr(i,2);
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
continue;
}
if (i+2==len-1)
{
can[i][3] = true;
temp = s.substr(i,3);
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
continue;
}
if (can[i+2][3] || (can[i+2][2] && s.substr(i,2)!=s.substr(i+2,2)))
{
temp = s.substr(i,2);
can[i][2]=true;
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
}
if (can[i+3][2] || (can[i+3][3] && s.substr(i,3)!=s.substr(i+3,3)))
{
temp = s.substr(i,3);
can[i][3]=true;
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
}
}
sort(a.begin(),a.end());
len = a.size();
printf("%d\n",len);
for (int i = 0;i <= len-1;i++)
puts(a[i].c_str());
return 0;
}

【16.67%】【codeforces 667C】Reberland Linguistics的更多相关文章

  1. codeforces 667C C. Reberland Linguistics(dp)

    题目链接: C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes inpu ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【16.23%】【codeforces 586C】Gennady the Dentist

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 807D】Dynamic Problem Scoring

    [题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...

  7. 【codeforces 67A】Partial Teacher

    [题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...

  8. 【codeforces 821E】Okabe and El Psy Kongroo

    [题目链接]:http://codeforces.com/problemset/problem/821/E [题意] 一开始位于(0,0)的位置; 然后你每次可以往右上,右,右下3走一步; (x+1, ...

  9. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. treap-名次树-树堆

    #include <cstring> #include <cstdio> #include <cstdlib> using namespace std; struc ...

  2. jmeter--十三种断言方式介绍

    jmeter中有个元件叫做断言(Assertion),它的作用和loadrunner中的检查点类似: 用于检查测试中得到的响应数据等是否符合预期,用以保证性能测试过程中的数据交互与预期一致. 使用断言 ...

  3. HibernateCRUD基础框架(3)-简单的和较为复杂的标准的CRUD API

    优点:简单的和基础的CRUD功能可以很快实现,可以说是比较的"标准化".维护起来也很容易. 缺点:性能没有保障.不支持特别复杂的CRUD. 可以适用的场景:小型Web项目 1.Cr ...

  4. C#复习题

    1.以下(D )不是 C#中方法的參数的类型. A.值类型B.引用型C.输出型D.属性 2.C#中的数据类型分为值类型和引用类型,以下(B )不属于引用类型. A.类 B.枚举 C.接口 D.数组 3 ...

  5. 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza

    [链接]h在这里写链接 [题意]     给你参赛者的数量以及一个整数S表示每块披萨的片数.     每个参数者有3个参数,si,ai,bi;     表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...

  6. thinkphp5项目--企业单车网站(八)(文章板块要点)(删除图片)

    thinkphp5项目--企业单车网站(八)(文章板块要点)(删除图片) 项目地址 fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise ...

  7. 数据结构与算法实验题 4.2 Who is the strongest

    数据结构与算法实验题 4.2 Who is the strongest ★实验任务 在神奇的魔法世界,召唤师召唤了一群的魁偶.这些魁偶排成一排,每个魁偶都有一个 战斗值.现在该召唤师有一个技能,该技能 ...

  8. Gora官方文档之二:Gora对Map-Reduce的支持 分类: C_OHTERS 2015-01-31 11:27 232人阅读 评论(0) 收藏

    参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ...

  9. 嵌入式/X86下linux系统死机及内存优化

    一.  CPU 过高或死锁导致系统卡死 1. CPU占用过高 (1)开线程太多导致CPU占用过高,系统卡死 解决:优化应用层业务逻辑,有些业务不必开线程就不开 (2)频繁清缓存导致读spi-flash ...

  10. Linux 系统 杀Oracle 进程

    Linux 系统 杀Oracle 进程 杀掉进程用此方法比较好,能保证杀得干净,而不是用SQL  alter system kill kill -9 `ps -ef|grep "oracle ...