The Australian voting system requires voters to sort all candidates by the degree of willingness to choose. One vote is a sort. The preferences of each vote are counted at the beginning. If a candidate wins more than 50% votes, he will directly win. Otherwise, all candidates tied for the lowest position will be out, however, those votes that rank the most out-of-office candidates in the first place will be re-counted as the highest-ranking non-out-of-office candidates. This screening process continues until a candidate receives more than 50% of the votes, or all candidates receive the same votes.
# Include <cstdio> # include <cstring> # include <iostream> # include <cmath> # include <algorithm> using namespace STD; const int n = 50; # define INF 0x3fffffffint vote [1050] [N]; int out [N], CNT [N]; char name [N] [100]; int num; int main () {int t, n, I, j; char STR [1000]; scanf ("% d", & T); While (t --) {scanf ("% d ", & N); getchar (); for (I = 1; I <= N; I ++) gets (name [I]); num = 0; while (gets (STR )! = NULL) {If (! Strcmp (STR, "") break; int Len = strlen (STR); int S = 0, K = 0; for (I = 0; I <Len; I ++) {If (STR [I]> = '0' & STR [I] <= '9 ') S = S * 10 + STR [I]-'0'; else {vote [num] [k ++] = s; S = 0 ;}} vote [num] [k ++] = s; num ++;} memset (Out, 0, sizeof (out); int flag = 0, rest = n, total = 0; while (rest> 1) // The number of unelected candidates exceeds 1 {Total = 0; // total number of votes memset (CNT, 0, sizeof (CNT )); for (I = 0; I <num; I ++) {for (j = 0; j <N; j ++) {If (! Out [vote [I] [J]) {CNT [vote [I] [J] ++; Total ++; break ;}}for (I = 1; I <= N; I ++) if (CNT [I] * 2> total &&! Out [I]) {printf ("% s \ n", name [I]); flag = 1; break;} If (FLAG) break; int mmin = inf, mMax = 0; for (I = 1; I <= N; I ++) {If (! Out [I]) {mmin = min (mmin, CNT [I]); mMax = max (mMax, CNT [I]) ;}} if (mmin = mMax) break; for (I = 1; I <= N; I ++) if (CNT [I] = mmin) {out [I] = 1; rest --;}} if (! Flag) {for (I = 1; I <= N; I ++) if (! Out [I]) printf ("% s \ n", name [I]);} If (T> 0) printf ("\ n") ;}return 0 ;}