zoukankan      html  css  js  c++  java
  • 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
    I am a slow walker,but I never walk backwards.
  • 相关阅读:
    【数学】Codeforces Round #470 (Div2) B
    【数学】At Coder 091 D题
    【2-SAT】The Ministers’ Major Mess UVALive – 4452
    【二分答案+2-SAT】Now or later UVALive
    【栈模拟dfs】Cells UVALive
    浅谈2-SAT(待续)
    【交叉染色法判断二分图】Claw Decomposition UVA
    【拓扑排序或差分约束】Guess UVALive
    【欧拉回路】UVA
    周总结8.15
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/5866445.html
Copyright © 2011-2022 走看看