Codeforces 709C 模拟
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'
'y'
'x'
'b'
'a'
'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.
What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
codeforces
bncdenqbdr
abacaba
aaacaba
String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.
题目连接:http://codeforces.com/contest/709/problem/C
题意:将s的子串进行一次变换,输出字典序最小的s。
思路:水题。注意一定要进行一次变换。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s;
char ans[];
int main()
{
int i;
cin>>s;
char ch;
int sign=,flag=;
for(i=; i<s.size(); i++)
{
if(s[i]->='a') ch=s[i]-;
else ch='z';
if(sign==&&ch<=s[i]) ans[i]=ch,flag=;
else if(flag==) ans[i]=s[i];
else ans[i]=s[i],sign=;
}
if(flag==) ans[i-]=ch;
for(i=; i<s.size(); i++)
printf("%c",ans[i]);
cout<<endl;
return ;
}
Codeforces 709C 模拟的更多相关文章
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- CodeForces - 404B(模拟题)
Marathon Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...
- Codeforces 709B 模拟
B. Checkpoints time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- CodeForces - 404A(模拟题)
Valera and X Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Codeforces 390A( 模拟题)
Inna and Alarm Clock Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64 ...
- Codeforces 452D [模拟][贪心]
题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的 ...
- CodeForces - 796B 模拟
思路:模拟移动即可,如果球落入洞中停止移动.注意:有可能第一个位置就是洞!! AC代码 #include <cstdio> #include <cmath> #include ...
- CodeForces - 864C-Bus-(模拟加油站问题)
https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...
- 【题解】Berland.Taxi Codeforces 883L 模拟 线段树 堆
Prelude 题目传送门:ヾ(•ω•`)o Solution 按照题意模拟即可. 维护一个优先队列,里面装的是正在运营中的出租车,关键字是乘客的下车时间. 维护一个线段树,第\(i\)个位置表示第\ ...
随机推荐
- BigDecimal空指针异常——个人应用
背景: 将数据库统计的数据,封装成了两个BigDecimal,此时要将两个BigDecimal进行运算.其中有一个没有数据的话,会报null(不管null值在前在后) 先上解决: 我把数据库的数据进行 ...
- 使用promisify来流程化异步操作
现代js包括nodejs中有很多函数都是异步执行的, 我们总是需要写一个回调函数并且作为最后以一个参数传入,而我希望的是能像写promise这样的回调 promise .then() .then() ...
- CSS个人笔记
1. CSS盒模型 1.1 控制元素尺寸属性 1.1.1 box-sizing: 改变元素应用的尺寸规则 当设置元素尺寸宽度为固定值时(eg: 100px), 其实是元素内容区域的宽度为100px, ...
- MySQL 查看执行的SQL记录
我们时常会有查看MySQL服务端执行的SQL记录.在MySQL5.1之后提供了支持,通过在启动时加入-l 或者--log选项即可: mysqld -l mysqld --log 在后面的版本(5.1. ...
- mysql更新(七) MySQl创建用户和授权
14-补充内容:MySQl创建用户和授权 权限管理 我们知道我们的最高权限管理者是root用户,它拥有着最高的权限操作.包括select.update.delete.update.grant等操作 ...
- Java集合入门
内容: 1.认识集合 2.Iterator迭代器 1.认识集合 (1)什么是集合 前面的学习,我们知道数据多了,使用数组存放.而且数组中存放的都是基本类型的数据,并且数组是定长的. 当在程序中创建的对 ...
- Js 动态设置DIV日期信息
HTML代码如下: <div id="time"> 2013年12月20日 14:49:02 星期五 </div> JS代码如下: window.onlo ...
- 折腾了好久,thinkphp5打开提示加载failed to open stream: No such file or directory in think start.php
GIT上下载的THINKPHP5记得先 composer update 我就是没update ,折腾了1个小时,才想起来这个事 thinkphp5默认首页打开空白 打开报错提示 提示thinkphp ...
- 21. oracle游标循环例子
事例1: create or replace procedure sp_addProjectQj( ret out number, flowid in number --流程Id) ascursor ...
- Appium清空EditText
在使用appium过程中,发现sendkeys和clear方法并不太好使,封装模拟手工一个一个删除 这里用到keyEvent,具体内容请参考api http://appium.github.io/ja ...