前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces 709C Letters Cyclic Shift

CodeForces 709C Letters Cyclic Shift

作者头像
ShenduCC
发布2018-04-27 10:54:25
5720
发布2018-04-27 10:54:25
举报
文章被收录于专栏:算法修养算法修养

C. Letters Cyclic Shift

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

input

代码语言:javascript
复制
codeforces

output

代码语言:javascript
复制
bncdenqbdr

input

代码语言:javascript
复制
abacaba

output

aaacaba

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;
const int maxn=1e5;
char a[maxn+5];
char fun(char x)
{
    char b=x;
    if(x=='a')
        b='z';
    else
        b--;
    return b;
}
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    int l=len-1,r=len-1;
    for(int i=0;i<len;i++)
    {
        if(l==len-1&&a[i]!='a')
            l=i;
        if(l!=len-1&&r==len-1&&a[i]=='a')
            r=i-1;
    }
    for(int i=0;i<len;i++)
    {
        if(i<=r&&i>=l)
            printf("%c",fun(a[i]));
        else
            printf("%c",a[i]);

    }
    printf("\n");
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-09-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档