当前位置:   article > 正文

Codeforces Round #700 (Div. 2)-A. Yet Another String Game-题解--三目运算符_#700div2

#700div2

Codeforces Round #700 (Div. 2)-A. Yet Another String Game

传送门
Time Limit: 2 seconds
Memory Limit: 512 megabytes

Problem Description

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=s1s2sn 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 1in) 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:

Input

Each test contains multiple test cases. The first line contains t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1t1000) — 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 1s50) consisting of lowercase English letters.

Output

For each test case, print the final string in a single line.

Sample Input

3
a
bbbb
az
  • 1
  • 2
  • 3
  • 4

Sample Onput

b
azaz
by
  • 1
  • 2
  • 3

Note

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

AC代码

#include <bits/stdc++.h>
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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/73208
推荐阅读
相关标签
  

闽ICP备14008679号