CF Vitaly and Strings
1 second
256 megabytes
standard input
standard output
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English letters, string s is lexicographically smaller than string t. Vitaly wondered if there is such string that is lexicographically larger than string s and at the same is lexicographically smaller than string t. This string should also consist of lowercase English letters and have the length equal to the lengths of strings s and t.
Let's help Vitaly solve this easy problem!
The first line contains string s (1 ≤ |s| ≤ 100), consisting of lowercase English letters. Here, |s| denotes the length of the string.
The second line contains string t (|t| = |s|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings s and t are the same and string s is lexicographically less than string t.
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them.
a
c
b
aaa
zzz
kkk
abcdefg
abcdefh
No such string
String s = s1s2... sn is said to be lexicographically smaller than t = t1t2... tn, if there exists such i, that s1 = t1, s2 = t2, ... si - 1 = ti - 1, si < ti.
思路:将字符串看成数字,先从左向右找到第一个不相同的,然后把最右边那位加一,如果超出了Z就进位。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; int main(void)
{
string s;
string t;
int loc,len,flag; cin >> s >> t;
if(s == t)
puts("No such string");
else
{
len = s.size();
flag = ; for(int i = ;i < len;i ++)
if(s[i] < t[i])
{
loc = i;
break;
}
if(s[loc] + < t[loc])
{
s[loc] += ;
flag = ;
}
else
{
int box = ;
int add = ;
for(int i = len - ;i > loc;i --)
{
flag = ;
s[i] += box + add;
if(s[i] > 'z')
{
s[i] = 'a';
add = ;
box = ;
}
else
{
add = ;
box = ;
}
}
s[loc] += add;
if(s == t)
{
puts("No such string");
return ;
}
}
if(flag)
cout << s << endl;
else
puts("No such string");
} return ;
}
CF Vitaly and Strings的更多相关文章
- codeforces 518A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- A. Vitaly and Strings
Vitaly is a diligent student who never missed a lesson in his five years of studying in the universi ...
- CF Set of Strings
Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 543C Remembering Strings
https://cn.vjudge.net/problem/CodeForces-543C 题目 You have multiset of n strings of the same length, ...
- CodeForces 518A Vitaly and Strings (水题,字符串)
题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间. 析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行. 代 ...
- CF 149E Martian Strings 后缀自动机
这里给出来一个后缀自动机的题解. 考虑对 $s$ 的正串和反串分别建后缀自动机. 对于正串的每个节点维护 $endpos$ 的最小值. 对于反串的每个节点维护 $endpos$ 的最大值. 这两个东西 ...
- CF 452E. Three strings(后缀数组+并查集)
传送门 解题思路 感觉这种题都是套路之类的??首先把三个串并成一个,中间插入一些奇怪的字符,然后跑遍\(SA\).考虑按照\(height\)分组计算,就是每个\(height\)只在最高位计算一次, ...
- cf 762C. Two strings
因为要删去1个串(读错题),所以就直接二分搞就好了. 需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了. #include<bits/stdc++.h> ...
随机推荐
- POJ 1751 Highways (最小生成树)
Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...
- (转)UML用例图总结
用例图主要用来描述“用户.需求.系统功能单元”之间的关系.它展示了一个外部用户能够观察到的系统功能模型图. [用途]:帮助开发团队以一种可视化的方式理解系统的功能需求. 用例图所包含的元素如下: 1. ...
- VIM技巧(1)
VIM技巧(1) 替换 36s/^\(.* = \)entity.\(.*\)$/\1this.GetShowName("\2",\2); 删除空行 %g/^$/d %g/^\s* ...
- 笔记:搭建Windows2003 VPN跳板
背景:有一台“墙外”主机,利用自建VPN 番羽 土啬.当然,如端口转发.加密代理等很多方法都可以实现上述目的,VPN只是其中一种. 环境:Win2003主机,一个网络接口,一个独立IP,端口不受限 ...
- VHDL TestBench基础(转)
TestBench的主要目标是: 实例化DUT-Design Under Test 为DUT产生激励波形 产生参考输出,并将DUT的输出与参考输出进行比较 提供测试通过或失败的指示 TestBench ...
- win8图片默认不显示
最近,发现了一个问题,在查看图片的时候,出现了这样的情况: 查看的时候很不方便,想要找到自己需要的图片就要误打误撞,也不知道自己在哪儿设置了,于是,上网查资料,才发现其实只需要简单的该一下设置就可以了 ...
- HibernateDaoSupport的使用
1.HibernateDaoSupport是有spring提供的一个hibernate模版工具类,或不多说,直接上代码 接口 IGenericDao.java package org.hibernat ...
- CSS 文本格式
整理自:(http://www.w3school.com.cn/css/css_text.asp) Text Color 颜色属性被用来设置文字的颜色. 颜色是通过CSS最经常的指定: 十六进制值 - ...
- 《JavaScript高级程序设计》 读书笔记(三)
操作符 递增和递减操作符 var num1 = 2; var num2 = 20; var num3 = --num1 + num2; // 等于 21 var num4 = num1 + num2; ...
- Hadoop对小文件的解决方式
小文件指的是那些size比HDFS的block size(默认64M)小的多的文件.不论什么一个文件,文件夹和block,在HDFS中都会被表示为一个object存储在namenode的内存中, 每一 ...