Gotta Catch Em' All!_Codeforces

来源:互联网 发布:网络公开课网站 编辑:程序博客网 时间:2024/04/28 15:29

2017年2月5日23:20:31

 这题 WA了两发,是因为, for循环中的判断条件成了,i<strlen(s) ,这样 每次循环都会 调用len函数 所以 应该先定义 一个变量等于strlen(s) 然后用常量作为循环条件  要谨记这个教训!

代码如下:

#include <stdio.h>#include <string.h>#define maxn 100001char s[maxn];int main(){    int n[8]={0};    scanf("%s",s);    for(int i=0;s[i]!='\0';i++){        if(s[i]=='B'){            n[1]++;        }        if(s[i]=='u'){            n[2]++;        }        if(s[i]=='l'){            n[3]++;        }        if(s[i]=='b'){            n[4]++;        }        if(s[i]=='a'){            n[5]++;        }        if(s[i]=='s'){            n[6]++;        }        if(s[i]=='r'){            n[7]++;        }    }    n[2]/=2;    n[5]/=2;    int num=maxn;    for(int i=1;i<=7;i++){        if(n[i]<num){            num=n[i];        }    }    printf("%d\n",num);    return 0;}
0 0