CodeForces A. Letters Cyclic Shift【字符串】

本文介绍了一种算法挑战,任务是在给定的字符串中选择一个非空子串,并将其中的所有字母按照英文字母表向前移动一位。目标是找到执行此操作后得到的字典序最小的字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. 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 thats1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.

刚做这首题的时候,宝宝也是很无语,一堆英文看不懂也就算了。。给的数据也让我分析不出来。。最后好不容易搞懂了,用JAVA写了一遍,超时,用C写,超时,最后用C++才给过了。。百度的时候发现了一个神奇的头文件#include<bits/stdc++.h>,据说包含了C++里的所有头文件,长姿势了,,,
code:
#include<bits/stdc++.h>
using namespace std;
int main() {
	string str;
	int i,j;
	cin>>str;
	for(i=0;i<str.size();i++){
		if(str[i]!='a'){
			break;
		}
	}
	for(j=i;j<str.size();j++){
		if(str[j]=='a'){
			break;
		}
		str[j]--;
	}
	if(i==str.size()){
		str[str.size()-1]='z';
	}
	cout<<str<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值