时间轴

2025-09-12

init


题目:

这题可以画一个状态机来看

image-20250912110341407

小红先手,如果整个串的元音字母是奇数,那么直接拿所有的串,小红胜

小红先手,如果整个串的元音字母是偶数,除非是0个,小红先手就输了;如果是非零,那么再拿一个奇数个元音字母字串后,至少还剩下2-1=1个元音子串,而这时小明要拿偶数个,只能拿0个,因此必定可以进入状态机的第三个,整个串剩下奇数个,而轮到小红拿奇数个了,直接拿走所有串,小红胜出。

因此,只要这个字符串有元音字母,就是小红胜出,fou’ze

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdbool.h>
#include <string.h>
bool isVowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' ||
c == 'E' || c == 'I' || c == 'O' || c == 'U') {
return true;
}
return false;
}

bool doesAliceWin(char *s) {
int vowel_num = 0;
int len;
len = strlen(s);
// 统计所有的元音数目
for (int i = 0; i < len; i++) {
if (isVowel(s[i])) {
vowel_num++;
}
}
if (vowel_num == 0) {
return false;
}

if (vowel_num % 2 == 0) { // 偶数
return true;
} else { // 奇数
return true;
}
}