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

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

Sample Onput

b
azaz
by

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;
}
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tisfy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值