寻找过半数的字符
#include <stdio.h> find(char* str, int n){ int i = 1; char temp = str[0]; int num = 1; while(i < n){ if(str[i] == temp){ num++; } else if(num == 0){ temp = str[i]; num = 0; } else{ num--; } i++; } printf("%c", temp); } main(){ char str[] = {'a', 'b', 'c', 'a', 'd', 'a', 'd', 'a', 'a', 'd'}; find(str, 10); }