CodeForces 518A Vitaly and Strings (水题,字符串)
字符串 and Codeforces 水题 strings
2023-09-11 14:17:19 时间
题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间。
析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行。
代码如下:
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <cmath> #include <map> #include <cctype> using namespace std; const int maxn = 1000 + 5; string s, t; int main(){ while(cin >> s >> t){ int n = s.size(); int cnt = 0; ++s[n-1]; if(s[n-1] > 'z'){ s[n-1] = 'a'; cnt = 1; } for(int i = n-2; i >= 0; --i){ s[i] += cnt; if(s[i] > 'z'){ s[i] = 'a'; cnt = 1; } else cnt = 0; } if(s == t) puts("No such string"); else cout << s << endl; } return 0; }
相关文章
- Java实现 LeetCode 606 根据二叉树创建字符串(遍历树)
- clisp 数字,字符,字符串
- java 11 增加了一系列的字符串处理方法,Optional 加强 ,改进的文件API
- 时间戳转换为时间字符串
- Python字符串如何转为bytes对象
- 【Shell基础】字符串删除
- Python字符串切片操作知识详解
- Python 入门(二)Unicode字符串
- shell 生成指定范围随机数与随机字符串 .
- Python3 replace()实现字符串替换
- C++每日面试之字符串自定义解压算法
- Leetcode 1209. 删除字符串中的所有相邻重复项 II(牛逼,终于过了)
- 【LeetCode】394. 字符串解码