I am a slow walker,but I never walk backwards. Abraham Lincoln

GeekZRF

Codeforces 709C 模拟

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
codeforces
Output
bncdenqbdr
Input
abacaba
Output
aaacaba
Note

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。

思路:水题。注意一定要进行一次变换。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 string s;
 6 char ans[100100];
 7 int main()
 8 {
 9     int i;
10     cin>>s;
11     char ch;
12     int sign=0,flag=0;
13     for(i=0; i<s.size(); i++)
14     {
15         if(s[i]-1>='a') ch=s[i]-1;
16         else ch='z';
17         if(sign==0&&ch<=s[i]) ans[i]=ch,flag=1;
18         else if(flag==0) ans[i]=s[i];
19         else ans[i]=s[i],sign=1;
20     }
21     if(flag==0) ans[i-1]=ch;
22     for(i=0; i<s.size(); i++)
23         printf("%c",ans[i]);
24     cout<<endl;
25     return 0;
26 }
View Code

 

 

 

 

posted on 2016-09-12 21:38  GeekZRF  阅读(299)  评论(0编辑  收藏  举报

导航