Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
思路: 用a数组记录不同的单词,b数组记录该单词的出现次数,每输入一个单词进行一次判断,如果a中没这个单词,则a中添加这个单词,如果已经出现过,那么对应的b[i]加1。
优点: 和其他进行多次循环,嵌套循环的方法相比,每次输入完进行判断,输入完毕便直接输出的效率显然更高~~也是刚刚做完,欢迎大家给予建议。acm/HDU,代码可AC。
#include<stdio.h>
#include<string.h>
int max(int a,int b) //比较两个数大小,返回大的值
{
if(a<b)return b;
else return a;
}
int main()
{
int n;
while(scanf("%d",&n)&&n!=0) //输入N个数,0结束
{
char a[1000][15]={0}; /*数组a[i]储存不同的单词,由于循环,进行