Rikka with Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

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
Input
The first line of the input contains an integer
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

• 首先，当字符串中y或时，Rikka 应直接停止操作，因为原串就时他能取得的最小串;
• 当字符串以z开头时，Rikka应将最左边的z拨动到a，此时的串变得更小，而Yuta应将Rikka拨动出的a拨动成b，因为此时b事Yuta能取得的最大串;
• 当字符串以y开头后面接着z时，Rikka应跳过y去拨动第一个z，此时获得了更小串，注意，此时不能拨动y因为，当Rikka拨动y为z时，Yuta立即停止游戏，Rikka取得的不是最优解，故不符合题意，应跳过y去拨动z为a，Yuta此时应将Rikka拨动的a拨动成b，同第二中情况。
• 在代码中应表现为，如果字符串没有z则直接返回原串，如果字符串中存在z且z前面没有东西或全是y则，应将第一个z变为b返回;

//1005
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char str[110];int len;
int main(){
int t;
scanf("%d",&t);
int j;
while(t--){
scanf("%s",str);
len =strlen(str);
for(j = 0 ; j < len && str[j] == 'y' ;j++);
if(str[j] == 'z') str[j] = 'b';
printf("%s\n",str);
}
return 0;
}

posted @ 2019-08-19 18:04  我不是张小毛  阅读(...)  评论(...编辑  收藏