传送门
Time Limit: 2 seconds
Memory Limit: 512 megabytes
Homer has two friends Alice and Bob. Both of them are string fans.
One day, Alice and Bob decide to play a game on a string s = s 1 s 2 … s n s = s_1 s_2 \dots s_n s=s1s2…sn of length n n n consisting of lowercase English letters. They move in turns alternatively and Alice makes the first move.
In a move, a player must choose an index i i i ( 1 ≤ i ≤ n 1 \leq i \leq n 1≤i≤n) that has not been chosen before, and change s i s_i si to any other lowercase English letter c c c that c ≠ s i c \neq s_i c=si.
When all indices have been chosen, the game ends.
The goal of Alice is to make the final string lexicographically as small as possible, while the goal of Bob is to make the final string lexicographically as large as possible. Both of them are game experts, so they always play games optimally. Homer is not a game expert, so he wonders what the final string will be.
A string a a a is lexicographically smaller than a string b b b if and only if one of the following holds:
Each test contains multiple test cases. The first line contains t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1≤t≤1000) — the number of test cases. Description of the test cases follows.
The only line of each test case contains a single string s s s ( 1 ≤ ∣ s ∣ ≤ 50 1 \leq |s| \leq 50 1≤∣s∣≤50) consisting of lowercase English letters.
For each test case, print the final string in a single line.
3
a
bbbb
az
b
azaz
by
In the first test case: Alice makes the first move and must change the only letter to a different one, so she changes it to ‘b’.
In the second test case: Alice changes the first letter to ‘a’, then Bob changes the second letter to ‘z’, Alice changes the third letter to ‘a’ and then Bob changes the fourth letter to ‘z’.
In the third test case: Alice changes the first letter to ‘b’, and then Bob changes the second letter to ‘y’.
Alice和Bob玩字符串游戏,Alice想让字符串字典序尽可能小,Bob想让尽可能大。他们都能修改字符串中未修改过的字符,Alice先手,问最终字符串长什么样。
一个字符只能修改一次,想要字符排序尽可能靠前,就尽可能修改最前面的字符
a*****
b*****
则第一个字符串必定小于第二个
所以Alice就在第一个未修改过的字符中,尽可能修改为a
但是如果这个字符恰好是a,那么就把它修改为b
#include
using namespace std;
int main()
{
int N;
cin >> N;
while (N--)
{
string s;
cin >> s;
for (int i = 0; i < s.size(); i++)
{
if (i % 2 == 0) //Alice
putchar((s[i] == 'a') ? 'b' : 'a'); //s[i]等于'a'吗? 如果是,putchar('b') 否则,putchar('a')
else //Bob
putchar((s[i] == 'z') ? 'y' : 'z'); //s[i]等于'z'吗? 如果是,putchar('y') 否则,putchar('z')
}
puts(""); //输出换行
}
return 0;
}