描述

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. DB2 添加license

    DB2 - DB2COPY1 - DB2-0 服务不能启动报的错是这样的:Microsoft Management Console   Windows 不能在 本地计算机 启动 DB2 - DB2.有 ...

  2. CentOS Vi编辑器

    vim:通过vim a.cfg进入文档 i:编辑状态 ESC:返回不可编辑状态 dd:在不可编辑状态下,dd可删除光标所在的行,2dd删除两行,以此类推 u:在不可编辑状态下,u可恢复删除的行 yy: ...

  3. angular 子路由

    const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', compo ...

  4. 变量声明和定义的关系------c++ primer

    为了允许把程序分成多个逻辑部分来编写,c++语言支持分离式编译机制 为了支持分离式编译,c++语言把声明和定义区分开来.声明(declaration)使得名字为程序所知,一个文件如果想使用别处定义的名 ...

  5. opencv.js小案例

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. linux下文件权限的介绍

    linux操作系统下,使用ll查看该目录下所有文件及其文件权限,以下是对文件权限的介绍 d代表的是目录(或称之为文件夹)   红框内的这3个是代表3个组的权限每组都是3个 第一组rwx代表是本用户的权 ...

  7. 连接池、数据源、JNDI三者间的关系及用法

    连接池:连接池是由容器(比如Tomcat)提供的,用来管理池中的连接对象.连接池自动分配连接对象并对闲置的连接进行回收.连接池中的连接对象是由数据源(DataSource)创建的.连接池(Connec ...

  8. Python实现——一元线性回归(最小二乘法)

    2019/3/24 线性回归--最小二乘法公式法 暂时用python成功做出来了图像,但是其中涉及到的公式还是更多的来自于网络,尤其是最小二乘法公式中的两个系数的求解,不过目前看了下书高数也会马上提及 ...

  9. SDUT OJ 数据结构实验之排序四:寻找大富翁

    数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...

  10. Linux 常用命令大全(长期更新)

    常见指令 打包压缩相关命令 关机/重启机器 Linux管道 vim使用 用户及用户组管理 文件权限管理 更改文件的用户及用户组 更改权限 常用指令 ls 显示文件或目录 -l 列出文件详细信息l(li ...