708A - Letters Cyclic Shift - CodeForces Solution


constructive algorithms greedy implementation strings *1200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.setf(ios::fixed), cout.precision(8);

    string s;
    cin >> s;

    int ok = 1;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != 'a' and ok) {
            int j = i;
            while (j < s.size() and s[j] != 'a') {
                s[j] = char(s[j] - 1);
                j++;
            }
            ok = 0;
            i = j - 1;
        }
    }

    if (ok == 1) s.back() = (s.back() == 'a' ? 'z': char(s.back() - 1));

    cout << s;

    return 0;
}


Comments

Submit
0 Comments
More Questions

38E - Let's Go Rolling
171G - Mysterious numbers - 2
1183C - Computer Game
400C - Inna and Huge Candy Matrix
417A - Elimination
222A - Shooshuns and Sequence
1736A - Make A Equal to B
1736B - Playing with GCD
887C - Solution for Cube
1737C - Ela and Crickets
1741C - Minimize the Thickness
1741A - Compare T-Shirt Sizes
1741D - Masha and a Beautiful Tree
109B - Lucky Probability
1741B - Funny Permutation
1741E - Sending a Sequence Over the Network
344B - Simple Molecules
370A - Rook Bishop and King
546E - Soldier and Traveling
1741G - Kirill and Company
1200B - Block Adventure
1088B - Ehab and subtraction
1270B - Interesting Subarray
478C - Table Decorations
1304C - Air Conditioner
1311C - Perform the Combo
1519C - Berland Regional
361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem