题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6684
解题心得:
- 因为是字典序,那么第一个字符肯定是最重要的,当它发生变化时无论之后的字符怎么变影响都可以忽略。所以这个游戏只会玩一轮。
- 其次就是如果第一个字符是,这个时候第一个人肯定都不会去动这个字符,谁动谁输,然后是看之后的第一个字符。
- 如果之后的字符是,那么这个会变成,否则直接终止什么都不改变。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+100;
char s[maxn];
int main() {
int t; scanf("%d", &t);
while(t--) {
scanf("%s", s);
int pos = -1, len = strlen(s);
for(int i=0;i<len;i++) {
if(s[i] != 'y') {
pos = i;
break;
}
}
if(pos == -1 || s[pos] != 'z') {
printf("%s\n", s);
} else {
s[pos] = 'b';
printf("%s\n", s);
}
}
return 0;
}