思路:用异或的性质;相同的数字异或的结果为0,且异或具有交换性,故所有101个数异或,最终结果即为只出现了一次的数据
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define M 5 //为方便测试,将101个数改为5个数
int main() {
int num[M];
int t = 0; //用于记录每次异或后的结果;
printf("Please input %d num:\n", M);
for (int i = 0; i < 5; ++i) {
scanf("%d", &num[i]);
}
for (int i = 0; i < 5; ++i) {
t = t ^ num[i];
}
printf("the num who appear just once is %d\n", t);
}