25 lines
583 B
C
25 lines
583 B
C
#include <stdbool.h>
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
|
||
bool canWinNim(int n) {
|
||
return n % 4 != 0;
|
||
}
|
||
|
||
int main(void) {
|
||
// 使用字符数组而不是字符串字面量,更省内存
|
||
char *result[] = {"false", "true"};
|
||
|
||
// 测试用例数组,避免重复的printf调用
|
||
int test_cases[] = {4, 1, 2, 3, 5};
|
||
int expected[] = {0, 1, 1, 1, 1}; // 期望结果:0=false, 1=true
|
||
|
||
for (int i = 0; i < 5; i++) {
|
||
int n = test_cases[i];
|
||
bool actual = canWinNim(n);
|
||
printf("n=%d: %s (期望:%s)\n", n, result[actual], result[expected[i]]);
|
||
}
|
||
|
||
return 0;
|
||
}
|