TOJ 2749 Absent Substrings
描述
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的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 后缀数组---New Distinct Substrings
Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...
- Codeforces Round #258 D Count Good Substrings --计数
题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...
- 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 ...
随机推荐
- (c++11)随机数------c++程序设计原理与实践(进阶篇)
随机数既是一个实用工具,也是一个数学问题,它高度复杂,这与它在现实世界中的重要性是相匹配的.在此我们只讨论随机数哦最基本的内容,这些内容可用于简单的测试和仿真.在<random>中,标准库 ...
- 灯塔AOI简易实现
首先我们来讨论下游戏开发中的几个坐标系,为了方便解释,我截取了灯塔AOI DEMO当NPC数目为0时候的样子(代码地址觉得有帮助的童鞋记得给我代码点个星^_^) 先对这张图简单说明下: 蓝色的坐标轴表 ...
- ubuntu14.10,解决按照最新版Gnome 15.10后,经典Gnome桌面字体问题!
ubuntu14.10刚安装完毕,我首先按照了经典Gnome桌面,随后我发现ubuntu软件中心里面能找到的软件明显不如先前我安装过的ubuntu了,我觉得有可能是因为我以前安装的ubuntu14.1 ...
- 《Think in Java》
chapter 1 对象导论 面向对象程序设计(Object-oriented Programming ,OOP) chapter 2 一切都是对象 字段和方法 若类的某个成员变量是基本数据类型,即是 ...
- NSURLSession 网络请求
1.NSURLSession 在 iOS9.0 之后,以前使用的 NSURLConnection 过期,苹果推荐使用 NSURLSession 来替换 NSURLConnection 完成网路请求相关 ...
- 已经上架的app在AppStore上搜不到的解决办法
1.问题呈现 相信很多人都遇到过这个问题,天天刷iTunes connect,终于发现app已经上架了,兴奋的跑过去告诉老板,老板说好,大家都装一个吧! 这时候只能一边不慌不忙地甩锅给苹果,一边快马加 ...
- Multimap的初使用
之前不知道这个类型使用,在朋友的推荐下进行了个实际操作. 类似这种查询,我需要将他们归类拿出来,如果招以前那么拿的话可能要套挺多个循环的. 首先根据查询得到一个 List<Map<Stri ...
- centos 在vm下网络不通
VMware是一款虚拟机,支持各种热门系统,我们可以在VMware虚拟机中安装其他系统以满足个人需求,但在为VMware安装CentOS6.5后,无法连接网络,这是什么原因导致的呢?下面就给大家介绍下 ...
- .NET Core 版本不支持的问题
分析一个.NET Core开源项目(Ocelot),打开后发现提示当前版本.NET Core 不支持. 错误信息如下: The current .NET SDK does not support ta ...
- 条目四《用empty来代替检查size()是否为0》
条目四<用empty来代替检查size()是否为0> 首先先说结论: empty()实现为内联函数.(众所周知, 优秀的内联函数的效率比一般函数是高的) 在stl标准库中,empty()对 ...