[CodeForces518A]Vitaly and Strings[字符串][构造]
2015-06-12 09:59
344 查看
题目链接:[CodeForces518A]Vitaly and Strings[字符串][构造]
题意分析:给出字符串s,t,问:是否有字符串,使得其大于s小于t。(s < t)
解题思路:题目即问:s的下一个排列是否小于t。
个人感受:下一个排列的构造我也是醉了。WA49都出来了XD
具体代码如下:
题意分析:给出字符串s,t,问:是否有字符串,使得其大于s小于t。(s < t)
解题思路:题目即问:s的下一个排列是否小于t。
个人感受:下一个排列的构造我也是醉了。WA49都出来了XD
具体代码如下:
#include <iostream> #include <string> using namespace std; typedef long long ll; int main() { string s1, s2, s3; cin >> s1 >> s2; int len = s1.size(); s3 = s1; for (int i = len - 1; i >= 0; i--) //s1的下一个排列 { if (s3[i] != 'z') { s3[i] += 1; break; } else s3[i] = 'a'; //有点像26进制的意味,从末尾开始进位,超过z就进位直到不进位为止 } if (s3 < s2) cout << s3 << '\n'; else cout << "No such string\n"; return 0; }
相关文章推荐
- 缺陷(bug)严重级别定义
- CocoaPods 里的 objc_msgSend
- 开源框架 KJFrameForAndroid
- Sass浅谈
- html 多选 select option 插件 multiselect 使用
- opencv MAT数据操作
- Freeplane快速上手笔记
- 学编程的重要性,你值得思考
- ASP.NET 预编译
- 7-5匹配颜色
- [D-VII] (数)晶体管2逻辑门2寄存器s
- Redhat6.4静默安装Oracle11g
- 【转】分布式与集群的区别
- 加入购物车动画效果
- 7-4暗调/高光
- SELinux 学习笔记
- 数据结构系列之平衡树(数组构建法)
- Python2中的raw_input() 与 input()
- SSH架构BaseDao实现
- Technical help article describing SPV within MultiBit