描述

Given a string of symbols, it’s natural to look it over and see what substrings are present. In this problem, you are given a string and asked to consider what substrings are absent. Of course, a given string has finite length and therefore only finitely many substrings, so there are always infinitely many strings that don’t appear as substrings of a given string. We’ll seek to find the lexicographically least string that is absent from the given string.

输入

Each line of input contains a string x over the alphabet {a, b, c}. x may be the empty string, as shown in the second line of the input sample below, or a nonempty string. The number of characters in the string x is no more than 250.

输出

For each input string x, find and output the lexicographically least string s over the alphabet {a, b, c} such that s is not a substring of x; i.e. s is absent from x. Since the empty string is a substring of every string, your output s is necessarily nonempty. Recall that a string is lexicographically less than another string if it is shorter or is the same length and alphabetically less; e.g. b

样例输入

bcabacbaa

aaabacbbcacc

样例输出

bb is absent from bcabacbaa
a is absent from
aac is absent from aaabacbbcacc

题目来源

台州学院第三届大学生程序设计竞赛

转换为进制转换的问题。

比如a,b,c,aa,ab,ac,ba...

分别看成1,2,3,4,5,6,7...

从1开始循环,然后使用find函数寻找字符串中是否(含有数字所对应的子串)。

一旦发现没有找到任何的子串就输出,跳出循环。

#include <stdio.h>
#include <string>
#include <iostream>
using namespace std; string convertToString(int n){
string t="",r="";
while(--n>=){
t+=n%+'a';
n/=;
}
for(int i=t.size()-; i>=;r+=t[i],i--);
return r;
} int main()
{
string str;
while(getline(cin,str)){
if(str.size()==){
cout<<"a is absent from "<<endl;
continue;
}
int k=;
while(){
string s=convertToString(k);
if(str.find(s)==string::npos){
cout<<s<<" is absent from "<<str<<endl;
break;
}
k++;
}
}
return ;
}

TOJ 2749 Absent Substrings的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  3. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  4. CSU-1632 Repeated Substrings (后缀数组)

    Description String analysis often arises in applications from biology and chemistry, such as the stu ...

  5. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  6. LA4671 K-neighbor substrings(FFT + 字符串Hash)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...

  7. 后缀数组---New Distinct Substrings

    Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...

  8. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

  9. tomcat The file is absent or does not have execute permission

    [root@centos02 bin]# ./startup.sh Cannot find ./catalina.sh The file is absent or does not have exec ...

随机推荐

  1. DataType--时间类型

    SQL SERVER 存储时间的方式和存放浮点数的方式类似,存放时按照一定公式算出一个数值,存放到页面,在读取时按照公式求算出时间值,再按照默认或指定的时间格式展示给用户. 如果存放DATETIME数 ...

  2. android studio中使用recyclerview小白篇(二)

    前面一个说了怎么把这个包引用进来,这一节说怎么做一个简单的例子出来,我也是照着别人的例子写的,然后慢慢改就行了,做好的效果如下图 1.在我们的activity_main中把recyclerview填加 ...

  3. DDD模式

    http://www.cnblogs.com/landeanfen/p/4816706.html https://www.cnblogs.com/malaoko/p/8732552.html

  4. java -jar jar包,运行报错没有主清单和无法加载主类

    jar: 包名(class 文件) META-INF(MANIFEST.MF ) .classpath 1.从eclipse直接导出的jar包: 2.修改MANIFEST.MF文件:

  5. JSON的key值为数字时如何使用

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript(Standard ECMA-262 ...

  6. java 关于数组 计数的面试题

    题目:用面向对象的方法求出数组中重复 value 的个数 :  1  出现:1 次3 出现:2 次8 出现:3 次2 出现:4 提供数组 :  int[] arr = {1,4,1,4,2,5,4,5 ...

  7. Android 应用资源及R文件的位置

    1.介绍 (1)常识 (2)在res目录下新建资源文件(例如数字资源) app--->res,选择res,右击new--->value resource file 2.字符资源(strin ...

  8. springMVC下载功能

    前台页面 <a href="download">下载</a> 后台代码 /** * 文件下载 * @param request * @return * @t ...

  9. 浏览器端 禁止 html 使用后退 或者替换后退功能..

    知乎大佬的代码: 作者:独夜行 链接:https://www.zhihu.com/question/40511430/answer/166467343 来源:知乎 著作权归作者所有.商业转载请联系作者 ...

  10. 洛谷 P2056 [ZJOI2007]捉迷藏 题解【点分治】【堆】【图论】

    动态点分治入 门 题? 题目描述 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩捉迷藏游戏.他们的家很大且构造很奇特,由 \(N\) 个屋 ...