A. Yet Another String Game

A. Yet Another String Game
time limit per test 2 seconds
memory limit per test 512 megabytes
input standard input
output standard output
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=s1s2…sn of length 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 (1≤i≤n) that has not been chosen before, and change si to any other lowercase English letter c that 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 is lexicographically smaller than a string b if and only if one of the following holds:
a is a prefix of b, but a≠b;
in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
Input
Each test contains multiple test cases. The first line contains t (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 (1≤|s|≤50) consisting of lowercase English letters.

Output
For each test case, print the final string in a single line.
Example
input
3
a
bbbb
az
output
b
azaz
by

My Answer Code:

/*
Author:Albert Tesla Wizard
Time:2021/2/24 16:30
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]=='a'&&i%2==0)s[i]='b';
            else if(s[i]=='z'&&i%2==1)s[i]='y';
            else if(i%2==0)s[i]='a';
            else if(i%2==1)s[i]='z';
        }
        cout<<s<<'\n';
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值