描述

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. QuotedStr函数

    今天学到一个新函数,很有用 QuotedStr(s);// 在s两边加单引号, 这样就不会看着n多的单引号糊涂了...

  2. [raspberry p3] suse wifi驱动加载

    问题 raspberry pi3安装后发现wifi 启动不了, brcmf_sdio加载失败了,return error code为-110 处理方法 打开 /etc/dracut.conf.d/ra ...

  3. winform panel显示子窗体

    private void ZiChuangTi() {//确认当前为子窗体 this.IsMdiContainer = true; //建立个子窗体的对象 Son mySon = new Son(); ...

  4. c++迭代递归实现汉诺塔(5种迭代方法满足你)

    #include <iostream> //从A到C using namespace std; int n; void ready() { cout << "请输入汉 ...

  5. Python登陆人人网

    #!coding:utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,password): #登 ...

  6. ulimit -n 查看可以打开的最大文件描述符的数量

    具体ulimit命令参考 https://www.cnblogs.com/wangkangluo1/archive/2012/06/06/2537677.html

  7. selenium滑动验证码操作

    1.首先要找到你要滑动的地方 2.调动鼠标事件按住不动 3.调整坐标即可 我这里是为了调试加了很多的sleep,print(hander)是为了看是否定位到了元素 4.效果如下图,但是我这里的验证文字 ...

  8. 百度分享,简单的一步操作解决你的网站不支持https访问的问题!

    百度分享,应该是目前最好用的前端分享插件了.然而,官方却没有支持https.现在越来越多的网站都走入https的安全加密队列了,那么在找不到更好地替代品的情况下,怎么能让它支持https呢? 答案当然 ...

  9. 使用C#来编写一个异步的Socket服务器

    介绍 我最近需要为一个.net项目准备一个内部线程通信机制. 项目有多个使用ASP.NET,Windows 表单和控制台应用程序的服务器和客户端构成. 考虑到实现的可能性,我下定决心要使用原生的soc ...

  10. java 的在线下载文件 .pdf

    java  的在线下载文件  .pdf 1.下载资源的本地位置 2.设置响应头 3.下载代码 1 PeriodicalResource periodicalResource = periodicalR ...