当前位置:网站首页>Maximum number of "balloons"

Maximum number of "balloons"

2022-07-05 05:27:00 low dog

Their thinking

First, we will count the variables of each letter , Let me create a variable for the final output ( That is, and all the minimum values , That is to say Number of whole words ), Then scan the input , adopt switch The function counts each letter on a line , Finally, after processing the counted variables , Compare the rows and assign the minimum value to the variable to be returned .

All the code

int nums(char* text){
    int b,a,l,o,n;
    int min=0;
    while(*text){
        switch(*text){
            case 'b':b++;break;
            case 'a':a++;break;
            case 'l':l++;break;
            case 'o':o++;break;
            case 'n':n++;break;
        }
        *text++;
    }
    l/=2;
    o/=2;
    min=b<a?b:a;
    min=min<l?min:l;
    min=min<o?min:o;
    min=min<n?min:n;
    return min;
}

原网站

版权声明
本文为[low dog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140622058449.html