The 1004 question is actually very simple, is wants you to count the most balloons the number, but in the output time but needs to be careful carefully, conforms to the question request.
In the output is the first note is the output order: If there are multiple numbers of the same color, first input first output, such as,
Red
Green
Red
Green
This situation requires an output
Red
Green
Post the AC code:
#include <stdio.h> #include <stdlib.h> #include <string.h>int main () {int n = 1;int i = 0;int max = 0;int Max index = 0;int j = 0;char Color[1000][16];int *cnum;while (n) {scanf ("%d", &n), cnum = (int *) malloc (sizeof (int) * n); for (i = 0;i < N;i + +) {scanf ("%s", &color[i]);} for (i = n-1;i >= 0;i--) {Cnum[i] = 1;if (i! = n-1) {for (j = n-1;j > I;j--) if (strcmp (color[i],color[j]) = = 0) { Cnum[i] + +;}}} max = Cnum[0];maxindex = 0;for (i = 0;i < N;i + +) {if (Max < cnum[i]) {max = Cnum[i];maxindex = i;}} for (i = 0;i < N;i + +) if (max = = Cnum[i]) {printf ("%s\n", Color[i]);}} return 0;}
Hangzhou Electric OJ 1004 realization and some traps of attention