Files
obsidian/C/T1/main.c
whatisnot 17f157e193 2025-8-16
2025-08-16 17:26:32 +08:00

25 lines
583 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}