ACM练习题

  • 题目:喜欢ACM的大一新生FYX同学来到了大学之后发现自己宿舍的同学各不相同;有的同学喜欢玩游戏;有的同学喜欢打篮球;有的喜欢和班级的男同学谈理想;有的同学喜欢喝班级的女同学谈人生。FYX也有自己独特的爱好,他喜欢判断一个由5个英文字符abcde组成的字符串中字符出现最多的次数。
  • #include <stdio.h>
    #include <math.h>
    #define MAXSIZE 100

    int main()
    {
        int i = 0,a = 0,b = 0,c = 0,d = 0,e = 0,max = 0;
        char str[MAXSIZE];
        scanf("%s",str);
        while(str[i] != '\0'){
            switch(str[i]){
            case 'a':a++;break;
            case 'b':b++;break;
            case 'c':c++;break;
            case 'd':d++;break;
            case 'e':e++;break;
          }
          i++;
        }
        if(a > max) max = a;
        if(b > max) max = b;
        if(c > max) max = c;
        if(d > max) max = d;
        if(e > max) max = e;
        
        printf("%d\n",max);
        return 0;
    }
     

猜你喜欢

转载自blog.csdn.net/Stephanie17395/article/details/82904250
今日推荐