CodeForces 518A Vitaly and Strings (水题,字符串)
题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间。
析:这个题当时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;
}
CodeForces 518A 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 #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- String.valueof;和String = ""+1;的区别
关于字符串的+操作,单纯的String s ="" +11;编译器会看做常量""和常量11的拼接操作,常量计算最快:String.valueOf会调用方法,速 ...
- 输入和输出(read,recv,recvmsg...和write,writev,writemsg)
每一个TCP套接口有一个发送缓冲区,可以用SO_SNDBUF套接口选项来改变这个缓冲区的大小. 应用进程调用 write时,内核从应用进程的缓冲区中拷贝所有数据到套接口的发送缓冲区.如果套接口的发送缓 ...
- 【转】UBUNTU 下GIT的安装
原文网址:http://www.cnblogs.com/perseus/archive/2012/01/06/2314069.html linux下软件的安装方式有多种,最简单的莫过于从软件中心直接安 ...
- Mysql 创建外键 1005 err 150
要看错误的详细提示,可以使用命令:(在MySQL Manual里搜索“errno 150”时找到) SHOW ENGINE INNODB STATUS; //针对用INNODB存储方式的数据库 ...
- Apache Tomcat8必备知识(完整的支持WebSockets 1.0)
一.Apache Tomcat 8介绍 Apache Tomcat 8RC1版于前几日发布.它 经过了2年的开发,引入了很多新特征,由于目前还只是Alpha版,故不推荐在产品中使用.但是我们应该了解它 ...
- kettle环境变量的设置和获取
1. 变量的类型Kettle 的早期版本中的变量只有系统环境变量目前版本中(3.1) 变量包括系统环境变量, "Kettle变量" 和内部变量三种 系统环境变量的影响范围很广,凡是 ...
- C++等语言中整型int等的取值范围计算方式
举short为例说明 如果以最高位为符号位,二进制原码最大为0111111111111111=2的15次方减1=32767.最小为1111111111111111=-2的15次方减1=-32767此时 ...
- PHP 通过实现 Iterator(迭代器)接口来读取大文件文本
读了NGINX的access日志,bnb_manage_access.log(31M) 和 bnb_wechat_access.log(50M) 附上代码: <?php /** * User: ...
- 面试总结之Linux/Shell
Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...
- 十一.jQuery源码解析之.pushStack()
pushStack()顾明思意,就是像桟中添加东西呗,现在看看他是如何添加东西的. 创建一个空的jQuery对象,然后把Dom元素集合放入这个jQuery对象中, 并保留对当前jQuery对象的引用. ...