首页 技术 正文
技术 2022年11月15日
0 收藏 997 点赞 2,923 浏览 3502 个字

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 longusing 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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848