思路:每输入一个字符串,跟前面的进行比较,如果有一样的前面的气球数量+1,如果没有气球种类加1
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
struct balloon //定义气球的结构体,存储每种气球的颜色和数量
{char cl[20];int count;
};int judge(char *p1,char *p2) //判断两个字符串是否相等;如果是指针的新手千万记得p1,p2指向的只是字符数组的首地址
{while(*p1==*p2 && *p1){p1++;p2++;} if(!*p1 && !*p2)return 1;elsereturn 0;
}
int main(int argc, char *argv[]) {int x;int n;int i;int key;int m;int max;char b[20];char maxball[20];struct balloon ball[1200];while(scanf("%d",&n) && n!=0){m=0;max=0;for(i=0;i<1200;i++) //一定要进行初始化,防止影响下一次的测试 {memset(ball[i].cl,'