CodeForces - 518A Vitaly and Strings(水题)
来源:互联网 发布:淘宝xbox360哪家店好 编辑:程序博客网 时间:2024/05/16 04:57
题意:
输入两个字符串s和t(只由小写字符组成),两个字符串的长度相同,s的字典序 < t的字典序。求一个字符串其字典序介于s和t之间。
解析:
显然求s的字典序+1最好,但是要保证最后是z的时候,要将当前位变为a,并且将下一位+1。
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int N = 105;char s[N], t[N], ans[N];int main() { while(scanf("%s%s", s, t) != EOF) { int len = strlen(s); strcpy(ans, s); for(int i = len-1; i >= 0; i--) { if(ans[i] == 'z') { ans[i] = 'a'; }else { ans[i]++; break; } } if(strcmp(ans, t) >= 0) puts("No such string"); else puts(ans); } return 0;}
0 0
- CodeForces - 518A Vitaly and Strings(水题)
- codeforces 518A Vitaly and Strings
- CodeForces 518A Vitaly and Strings
- codeforces 293 dvi2 A. Vitaly and Strings
- A. Vitaly and Strings
- A. Vitaly and Strings
- A. Vitaly and Strings
- 【Code Forces】518A Vitaly and Strings(思维题)
- CF 518A(Vitaly and Strings-构造)
- 518A - Vitaly and Strings【string】
- Codeforces Round #293 (Div. 2)A. Vitaly and Strings
- Codeforces Round #293 (Div. 2) -- A. Vitaly and Strings
- Codeforces Round #293 (Div. 2)--A-- Vitaly and Strings - Painting
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings(思路)
- Codeforces 595A Vitaly and Night 【水题】
- CF(#293 div2):A:Vitaly and Strings
- CF 293 A. Vitaly and Strings
- Codeforces Round #293 (Div. 2) -- A. Vitaly and Strings (字符串构造)
- Dubbo源码分析(一):概览
- 80+ Best Responsive Admin Templates Free & Premium
- 【Android开发经验】关于“多线程断点续传下载”功能的一个简单实现和讲解
- 站立会议
- POJ3125 printer(队列的使用)
- CodeForces - 518A Vitaly and Strings(水题)
- php 获取用textarea保存到数据库的内容,显示到页面保持换行
- Fiddler显示响应时间
- rabbitvcs
- Saltstack介绍
- CentOS5.8编译安装MySQL5.6.10
- IE8,IE9不支持ajaxSubmit
- bluez 协议栈实现1-概述
- CodeForces - 518B Tanya and Postcard(水题)