0
点赞
收藏
分享

微信扫一扫

CodeForces 709C Letters Cyclic Shift

大柚子top 2022-10-18 阅读 91

C. Letters Cyclic Shift

time limit per test

memory limit per test

input

output
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'.
s

Input
s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Output
s

Examples

input
codeforces
output
bncdenqbdr
input
abacaba
output

aaacaba


#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;
}






举报

相关推荐

0 条评论