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.
  • 相关阅读:
    python基础--文件操作实现全文或单行替换
    python基础7--集合
    python读写json文件
    python基础6--目录结构
    python基础5--模块
    Ubuntu的一些常用快捷键
    ubuntu dpkg 命令详解
    linux(Ubuntu)安装QQ2013
    fcitx-sogoupinyin下载地址和安装
    Ubuntu下装QQ2014
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/5866445.html
Copyright © 2011-2022 走看看