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> ...
随机推荐
- ORM 是一种讨厌的反模式
本文由码农网 – 孙腾浩原创翻译,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! (“Too Long; Didn’t Read.”太长不想看,可以看这段摘要 )ORM是一种讨厌的反模式,违背 ...
- JSF 2 listbox example
In JSF, <h:selectOneListbox /> tag is used to render a single select listbox – HTML select ele ...
- hdu 1429 胜利大逃亡(续)(bfs+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- [iOS基础控件 - 6.11.4] storyboard 的 Segue
A.概念 storyboard中的跳转事件连线,都是一个UIStoryboardSegue对象(Segue) 来源控制器 触发控制器 目标控制器 跳转到的控制器 Seg ...
- uva 1356 Bridge ( 辛普森积分 )
uva 1356 Bridge ( 辛普森积分 ) 不要问我辛普森怎么来的,其实我也不知道... #include<stdio.h> #include<math.h> #inc ...
- Starter Set of Functional Interfaces
Java Development Kit 8 has a number of functional interfaces. Here we review the starter set-the int ...
- Unity3D之Mecanim动画系统学习笔记(七):IK(反向动力学)动画
什么是IK? IK(Inverse Kinematics)即反向动力学,即可以使用场景中的各种物体来控制和影响角色身体部位的运动,一般来说骨骼动画都是传统的从父节点到子节点的带动方式(即正向动力学), ...
- VirtualBox虚拟磁盘扩容
1. cmd中运行 VBoxManage modifyhd D:\我的资料库\Documents\VirtualBox VMs\ubuntu\ubuntu.vdi --resize 提示错误 Syn ...
- 回顾JDBC
最近因为公司的需要,一直在做我司商城的修改和维护,好几个月没有接触过java的代码了,有点手生,就算是开发java 的web项目,持久层习惯用hibernate,jdbc很少用.hibernate实现 ...
- window.open()打开窗口的几种方式
1. window.open("http://www.baidu.com/", "_search");//在一个新的窗口打开百度,并且使URL地址出现在搜索栏中 ...