zoukankan      html  css  js  c++  java
  • AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心

    A. Letters Cyclic Shift

    题目连接:

    http://www.codeforces.com/contest/708/problem/A

    Description

    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.

    Sample Input

    codeforces

    Sample Output

    bncdenqbdr

    Hint

    题意

    你可以调整一个子串,使得这个子串的所有字符都往前减小一个字典序,问你能够得到的最小字典序的字符串是哪个

    题解:

    贪心,从前往后,能变就变。

    特判掉全是a的情况就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    string s;
    int main()
    {
        cin>>s;
        int i;
        for(i=0;i<s.size();i++)
            if(s[i]!='a')break;
        int flag = 0;
        for(int j=i;j<s.size();j++)
        {
            if(s[j]=='a')break;
            s[j]--;
            flag=1;
        }
        if(i==s.size())s[i-1]='z';
        cout<<s<<endl;
    }
  • 相关阅读:
    sklearn Pipeline 和Ploynomial
    python PCA
    python numpy 包积累
    python 画图
    Sklearn——逻辑回归
    R语言链接数据库
    R语言清空环境所有变量
    wordpress调用文件
    WordPress时间日期函数常用代码
    如何使WordPress博客添加多个sidebar侧边栏
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5830529.html
Copyright © 2011-2022 走看看