A. Letters Cyclic Shift

题目连接:

http://www.codeforces.com/contest/708/problem/A

Description

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?

Input

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Output

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

Sample Input

codeforces

Sample Output

bncdenqbdr

Hint

题意

你可以调整一个子串,使得这个子串的所有字符都往前减小一个字典序,问你能够得到的最小字典序的字符串是哪个

题解:

贪心,从前往后,能变就变。

特判掉全是a的情况就好了

代码

#include<bits/stdc++.h>
using namespace std; string s;
int main()
{
cin>>s;
int i;
for(i=0;i<s.size();i++)
if(s[i]!='a')break;
int flag = 0;
for(int j=i;j<s.size();j++)
{
if(s[j]=='a')break;
s[j]--;
flag=1;
}
if(i==s.size())s[i-1]='z';
cout<<s<<endl;
}

AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心的更多相关文章

  1. codeforce AIM tech Round 4 div 2 B rectangles

    2017-08-25 15:32:14 writer:pprp 题目: B. Rectangles time limit per test 1 second memory limit per test ...

  2. AIM Tech Round 3 (Div. 2) (B C D E) (codeforces 709B 709C 709D 709E)

    rating又掉下去了.好不容易蓝了.... A..没读懂题,wa了好几次,明天问队友补上... B. Checkpoints 题意:一条直线上n个点x1,x2...xn,现在在位置a,求要经过任意n ...

  3. AIM Tech Round 3 (Div. 2) A , B , C

    A. Juicer time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  4. codeforces 709C C. Letters Cyclic Shift(贪心)

    题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路 ...

  5. AIM Tech Round 4 (Div. 2)ABCD

    A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. AIM Tech Round 4 (Div. 2)(A,暴力,B,组合数,C,STL+排序)

    A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  7. AIM Tech Round 3 (Div. 2)

    #include <iostream> using namespace std; ]; int main() { int n, b, d; cin >> n >> ...

  8. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  9. AIM Tech Round 3 (Div. 2) B

    Description Vasya takes part in the orienteering competition. There are n checkpoints located along ...

随机推荐

  1. ASP.NET MVC学习笔记-----ControllerFactory

    上面这张图是asp.net mvc的工作流程图,我们可以看到当一个http请求来临时,首先需要经过路由系统,路由系统从中获取一些路由信息,然后ControllerFactory根据所得到的路由信息生成 ...

  2. Sublime Text 之运行 js 方法[2015-5-6更新mac下执行js]

    昨天说完<Sublime Text 2 绿化与汉化 [Windows篇]>,今天我们来说说怎么用st直接运行 js 吧.群里的小伙伴一直对我的 ST 能直接运行js感到非常好奇,今天我就公 ...

  3. 分模块开发创建Action子模块——(九)

    web层选择war打包方式. 1.右击父工程新建maven模块

  4. Linux信号(signal)机制【转】

    转自:http://gityuan.com/2015/12/20/signal/ 信号(signal)是一种软中断,信号机制是进程间通信的一种方式,采用异步通信方式 一.信号类型 Linux系统共定义 ...

  5. On the Bias/Variance tradeoff in Machine Learning

    参考:https://codesachin.wordpress.com/2015/08/05/on-the-biasvariance-tradeoff-in-machine-learning/ 之前一 ...

  6. JDK7的新玩具java.util.Objects

    空指针异常这个坑爹的异常是初学开发者最常见的坑,那么今天为大家分享一个jdk的新工具java.util.Objects包.里面有很多工具可以帮我们避免空指针异常让我我们的代码写起来更加优雅.下面我们来 ...

  7. POJ 3666 Making the Grade(二维DP)

    题目链接:http://poj.org/problem?id=3666 题目大意:给出长度为n的整数数列,每次可以将一个数加1或者减1,最少要多少次可以将其变成单调不降或者单调不增(题目BUG,只能求 ...

  8. ansible源码解读

    Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansibl ...

  9. CAS单点登录流程

    CAS的官方站点: https://apereo.github.io/cas/5.2.x/index.html 概念解读: The TGT (Ticket Granting Ticket), stor ...

  10. CI框架中自带的加密解密如何应用

    首先我们找到配置文件application/config/config.php  ,找到如下代码: ? 1 $config['encryption_key'] = "YOUR KEY&quo ...