codeforces666A
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
abacabaca
3
aca
ba
ca
abaca
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的更多相关文章
随机推荐
- JavaWeb应用系统开发实训任务(一)
项目描述: 随着家长对孩子教育的日渐重视,社区幼儿学校在国内逐渐兴起,对社区幼儿学校的信息化管理成为迫切需求.社区幼儿学校管理系统需要实现以下功能: 1) 教师管理:实现对教师信息的查询.删除.增加 ...
- Django+celery+rabbitmq实现邮件发送
一.环境 1.pip包 amqp==2.4.2 anyjson==0.3.3 billiard==3.6.0.0 celery==4.3.0 Django==2.2 dnspython==1.16.0 ...
- MySQL的简介、启动及其DDL
MySQL的各项配置: 默认会启用TCP/IP网络: 默认客户端/服务器端口:3306: 将数据库的BIN目录写入Windows的的path环境变量: 默认不允许root用户在其他机器上远程登录: M ...
- centos7.4 安装 .net core 2.2
Step 1:首先注册Microsoft签名密钥,每台机器注册一次就行. sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/pack ...
- C#中操作单个cookie和cookie字典
单个cookie和cookie字典在浏览器中的存储格式如下:可以看到,单个cookie是以单一键值对的方式存储的,而cookie字典的值包含多个键值对,这些键值对之间以&符号拼接.cookie ...
- git的详细安装
git的详细安装 Git 是时候动手尝试下 Git 了,不过得先安装好它.有许多种安装方式,主要分为两种,一种是通过编译源代码来安装:另一种是使用为特定平台预编译好的安装包. 从源代码安装 若是条件允 ...
- JS基础_关系运算符
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- O061、Boot from Volume
参考https://www.cnblogs.com/CloudMan6/p/5679384.html Volume 除了可以用作Instance的数据盘,也可以作为启动盘(Bootable Vol ...
- sass之mixin的全局引入(vue3.0)
sass之mixin的全局引入(vue3.0) 1.scss文件(mixin.scss) /* 渐变 */ @mixin gradual($color, $color1){ background: $ ...
- mac 下开发golang 配置
1.安装golang 见附件 2.默认安装在 /usr/local/go 目录下 3.配置环境变量: 编辑文件:vim /etc/profile,有的MAC 下没有这个文件,可以新建. 加入环境变量 ...