关于ACM Let the Balloon Rise问题求助
#include <stdio.h>
#include <string.h>
int main(){
int num, i, k, j, max, times;
char **array;
char maxColor[21];
while (scanf("%d", &num) != EOF && num != 0)
{
getchar();
array = (char **)malloc(sizeof(char*)*num);
for (i = 0; i < num; i++)
{
array[i] = (char *)malloc(sizeof(char)* 21);
gets(array[i]);
}
max = 0;
times = 0;
for (k = 0; k < num; k++)
{
for (j = 0; j < num; j++)
{
if (strcmp(array[k], array[j]) == 0)
{
times++;
}
}
if (times > max)
{
max = times;
strcpy(maxColor, array[k]);
}
}
printf("%s\n", maxColor);
free(array);
}
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h> //加
int main(){
int num, i, k, j, max, times;
char **array;
char maxColor[21];
while (scanf("%d", &num) != EOF && num != 0)
{
getchar();
array = (char **)malloc(sizeof(char*)*num);
for (i = 0; i < num; i++)
{
array[i] = (char *)malloc(sizeof(char)* 21);
gets(array[i]);
}
max = 0;
//删times = 0;
for (k = 0; k < num; k++)
{
times = 0;//加
for (j = 0; j < num; j++)
{
if (strcmp(array[k], array[j]) == 0)
{
times++;
}
}
if (times > max)
{
max = times;
strcpy(maxColor, array[k]);
}
}
printf("%s\n", maxColor);
free(array);
}
}