//统计数组中出现次数超过一半的数字 #include <stdio.h> int Find(int *arr, int len) { int num = 0; //当前数字 int times = 0; //当前数字出现的次数 int i = 0; for (i = 0; i<len; i++) { if (times == 0) { num = arr[i]; times = 1; } else if (arr[i] == num) times++; else times--; } return num; } int main() { int arr[] = { 1, 5, 5.2, 5, 4, 3, 5, 5, 5 }; printf("超过一半的数是:%d ", Find(arr, sizeof(arr) / sizeof(arr[0]))); return 0; }