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 ...
随机推荐
- AES加密 AESCrypt 类
/// <summary> /// AES加密 /// </summary> public sealed class AESCrypt { /// <summary> ...
- 申请免费通配符证书(Let's Encrypt)并绑定IIS(转载)
本文转载自https://blog.csdn.net/qq_41608008/article/details/80491447 什么是 Let's Encrypt? 部署 HTTPS 网站的时候需要证 ...
- 全新的membership框架Asp.net Identity
在Asp.net上,微软的membershop框架经历了Asp.net membership到Asp.net simple membership,再到现在的Asp.net Identity. 每一次改 ...
- 复杂业务下向Mysql导入30万条数据代码优化的踩坑记录
从毕业到现在第一次接触到超过30万条数据导入MySQL的场景(有点low),就是在顺丰公司接入我司EMM产品时需要将AD中的员工数据导入MySQL中,因此楼主负责的模块connector就派上了用场. ...
- VSCode提示pylint isnot installed
1.下载所需扩展 在https://www.lfd.uci.edu/~gohlke/pythonlibs/中下载所需扩展,我下载的是:pylint-2.1.1-py2.py3-none-any.whl ...
- 18、OpenCV Python 简单实现一个图片生成(类似抖音生成字母人像)
__author__ = "WSX" import cv2 as cv import numpy as np def local_threshold(img): #局部阈值 gra ...
- SDUT OJ 图结构练习——最短路径 ( Floyed 算法 AND Dijkstra算法)
图结构练习——最短路径 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- [HAOI2011]Problem b BZOJ2301 数学
题目描述 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 输入输出格式 输入格式: 第一行一个整数 ...
- 5、Numpy处理数据
转载自:http://old.sebug.net/paper/books/scipydoc/numpy_intro.html#id9 2 NumPy-快速处理数据 标准安装的Python中用列表(li ...
- LeetCode记录之20——Valid Parentheses
09.18更新算法采用栈的思想解决,方法①所示. 本题主要是找是否有匹配的字符串,因为还没有复习到栈之类的知识点,只能还是采用暴力方法了,后期会补上更加优化的算法.我的思路就是先遍历一遍找是否有匹配的 ...