zoukankan      html  css  js  c++  java
  • CodeForces 709C Letters Cyclic Shift

    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

    #include <iostream>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #include <stdio.h>
    #include <algorithm>
    #include <string>
    
    using namespace std;
    const int maxn=1e5;
    char a[maxn+5];
    char fun(char x)
    {
        char b=x;
        if(x=='a')
            b='z';
        else
            b--;
        return b;
    }
    int main()
    {
        scanf("%s",a);
        int len=strlen(a);
        int l=len-1,r=len-1;
        for(int i=0;i<len;i++)
        {
            if(l==len-1&&a[i]!='a')
                l=i;
            if(l!=len-1&&r==len-1&&a[i]=='a')
                r=i-1;
        }
        for(int i=0;i<len;i++)
        {
            if(i<=r&&i>=l)
                printf("%c",fun(a[i]));
            else
                printf("%c",a[i]);
    
        }
        printf("
    ");
        return 0;
    }



  • 相关阅读:
    我了解到的新知识之----如何使用Python获取最新外汇汇率信息
    软工实践个人总结
    第06组 Beta版本演示
    第06组 Beta冲刺(5/5)
    第06组 Beta冲刺(4/5)
    第06组 Beta冲刺(3/5)
    第06组 Beta冲刺(2/5)
    第06组 Beta冲刺(1/5)
    第06组 Alpha事后诸葛亮
    第06组 Alpha冲刺(6/6)
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228588.html
Copyright © 2011-2022 走看看