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.
  • 相关阅读:
    Javascript 之 构造函数
    MySQL无法创建外键、查询外键的属性
    企业该如何进行高效IT运维管理
    提高工作效率:15个有用的项目管理工具
    JavaScript AJAX stream 流式显示
    “后PC”时代来临
    Oracle 11gR2 Database和Active Data Guard迁移案例
    亲历腾讯WEB前端开发三轮面试经历及面试题
    基于jquery的页面代码的优化
    HTML5简略介绍
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/5866445.html
Copyright © 2011-2022 走看看