Files
obsidian/C/T1/main.c
whatisnot 59d64954ed 2
2025-08-14 15:19:34 +08:00

38 lines
1.1 KiB
C
Raw 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) {
// 如果石头数量是4的倍数先手必输
// 否则先手必胜
return n % 4 != 0;
}
int main(void) {
// 测试用例1: n = 4, 期望输出: false
int n1 = 4;
bool result1 = canWinNim(n1);
printf("石头数量 %d: %s\n", n1, result1 ? "true (能赢)" : "false (不能赢)");
// 测试用例2: n = 1, 期望输出: true
int n2 = 1;
bool result2 = canWinNim(n2);
printf("石头数量 %d: %s\n", n2, result2 ? "true (能赢)" : "false (不能赢)");
// 测试用例3: n = 2, 期望输出: true
int n3 = 2;
bool result3 = canWinNim(n3);
printf("石头数量 %d: %s\n", n3, result3 ? "true (能赢)" : "false (不能赢)");
// 额外测试用例
int n4 = 3;
bool result4 = canWinNim(n4);
printf("石头数量 %d: %s\n", n4, result4 ? "true (能赢)" : "false (不能赢)");
int n5 = 5;
bool result5 = canWinNim(n5);
printf("石头数量 %d: %s\n", n5, result5 ? "true (能赢)" : "false (不能赢)");
return 0;
}