HDU 6684 Rikka with Game

Rikka with Game

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)

Problem Description

Though both Rikka and Yuta are busy with study, on their common leisure, they always spend time with each other and sometimes play some interesting games.

Today, the rule of the game is quite simple. Given a string s with only lowercase letters. Rikka and Yuta need to operate the string in turns while the first operation is taken by Rikka.

In each turn, the player has two choices: The first one is to terminate the game, and the second one is to select an index i of s and right shift the value of char si, i.e., a→b,b→c,…,y→z,z→a.

If the game is still alive after 2101 turns, i.e., after Yuta finishes his 2100 turns, the game will end automatically. The final result is the value of s when the game is over.

Now, Rikka wants to minimize the lexicographical order of the result while Yuta wants to maximize it. You are required to calculate the result of the game if both Rikka and Yuta play optimally.

For two string a and b with equal length m, a is lexicographically smaller than b if and only if there exists an index i∈[1,n] which satisfies ai

Input

The first line of the input contains an integer T(1≤T≤100), the number of test cases.

For each test case, the input contains a single line with a single string with only lowercase letters, the initial value of s(1≤|s|≤100).

Output

For each test case, output a single line with a single string, the answer.

Sample Input

2
a
zbc

Sample Output

a
bbc

题意:

有两个人,他们每次都有两个选择,一个是终止比赛,一个就是把字母右移一位比如a - b,b - c,他们一个要使字符串尽可能最大,一个使之最小,问最后的字符串。

思路:

因为使使字符串尽可能大的先手,所以就先要看看开头是否有连续的
y,z, 举个例子
yzyzx :
先手:yayzx
后手:ybyzx
这个时候加入假如先手变z的话,后手就可以转b,这样不会尽可能小了,所以只能终止,假如在z之前有y的话,后手也是不可能右移的,不然先手后就会变成a了。
总结起来就是s字符串开头开始有y就继续,有z的话把z变成b,直接break。

#include 
#include 
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    int t;
    string s;
    cin >> t;
    while (t--) {
        cin >> s;
        for (int i = 0; i < s.size() && (s[i] == 'z' || s[i] == 'y'); i++) {
            if (s[i] == 'z') {
                s[i] = 'b';
                break;
            }
        }
        cout << s << endl;
    }
    return 0;
}

你可能感兴趣的:(HDU)