CodeForces A. Letters Cyclic Shift【字符串】
2016-09-06 11:22
176 查看
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
output
input
output
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:
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; }
相关文章推荐
- Codeforces Aim Tech Round 3 (Div.2 )C.Letters Cyclic Shift 【贪心】水题
- codeforce708A-Letters Cyclic Shift
- Hongcow Learns the Cyclic Shift CodeForces - 745A
- 745 A. Hongcow Learns the Cyclic Shift codeforces
- Codeforces Gym 101164 K. Cutting (字符串 HASH)
- 【Codeforces Round 336 (Div 2) B】【水题 前缀和】Hamming Distance Sum 双字符串所有位置匹配下的差异数之和
- 【codeforces 709C】Letters Cyclic Shift
- Educational Codeforces Round 9-C. The Smallest String Concatenation(字符串排序)
- Codeforces Round #173 (Div. 2) / 282C XOR and OR (字符串处理)
- Codeforces Round #329 (Div. 2)A 字符串处理
- Codeforces Round #166 (Div. 2)D. Good Substrings(字符串散列)
- Codeforces Round #253 (Div. 2) A. Anton and Letters
- Codeforces Round #424 (Div. 2) B. Keyboard Layouts(字符串处理)
- [CF709C] Letters Cyclic Shift(暴力)
- Pasha Maximizes CodeForces - 435B 【字符串处理+贪心思想】
- Codeforces Round #291 (Div. 2) C - Watto and Mechanism 字符串
- codeforces gym 101164 K Cutting 字符串hash
- Educational Codeforces Round 36 (Rated for Div. 2)D. Almost Acyclic Graph(正解!!百度的那些拓扑排序现在都已经TLE!)
- Codeforces round 244(div.2) D match&catch【字符串hash】
- Codeforces Round #253 (Div. 2)A. Anton and Letters