博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)
阅读量:6949 次
发布时间:2019-06-27

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

C. Reberland Linguistics

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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.

 

 写了两天,才搞定。

in a row 是后来才注意到的,但是我还是认为不会影响什么,一直认为以前出现过就不行,最后问了学姐,给了一组样例。

zzzzz cf aaa aa aaa,不能出现相邻的相同的。

一下子考虑四个或者六个。

#include 
#include
#include
#include
#include
using namespace std;const int maxn = 1e4+5;int dp[maxn][5];set
ans;int main(){ string s; cin>>s; int n = s.size(); if(n<=6) { printf("0\n"); return 0; } if(n>=7) { string s1=""; s1 = s1+s[n-2]+s[n-1]; ans.insert(s1); dp[n-2][2] = 1; } if(n>=8) { string s1; s1 = s1+s[n-3]+s[n-2]+s[n-1]; ans.insert(s1); dp[n-3][3] = 1; } for(int i=n-4;i>=5;i--) { string s1="",s2 = ""; s1 = s1+s[i]+s[i+1]; s2 = s2+s[i+2]+s[i+3]; // cout<
<
::iterator it = ans.begin();it!=ans.end();it++) { cout<<*it<

 

转载于:https://www.cnblogs.com/littlepear/p/5844144.html

你可能感兴趣的文章
了解大数据的特点、来源与数据呈现方式
查看>>
spring 组件扫描配置说明component-scan
查看>>
Clarke and five-pointed star
查看>>
设计模式系列2-----C++实现责任链模式(Chain of Responsibility)
查看>>
20189312任方园《网络攻防》第六次作业
查看>>
929. Unique Email Addresses
查看>>
php
查看>>
职场人的“存在主义”哲学
查看>>
全互联结构D***综合配置示例
查看>>
在路上【我与51CTO的故事】
查看>>
演示:外部全局地址与外部局部地址的使用案例
查看>>
Elasticsearch集群监控与报警原理解析
查看>>
离开网易的转型之路2:无悔选择测试之路-路上的抉择、进取
查看>>
2014年中回首与展望
查看>>
局域网共享
查看>>
mysql建表-主键-索引-外键
查看>>
Android Studio第三十期 - 介绍几种网络请求方式写法
查看>>
计划任务导致的邮件系统故障
查看>>
《从零开始学Swift》学习笔记(Day 35)——会使用下标吗?
查看>>
盛大私有化和陈天桥的土皇帝心态
查看>>