题解 | #计算某字符出现次数#

计算某字符出现次数

http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

#include <string.h>

int main()
{
    int i,cet=0;
    char str[1111]={0},a;
     fgets(str, sizeof(str), stdin);
    scanf("%c",&a);
    if(65<=a&&a<=90)
    {
        for(i=0;i<1000;i++)
    {
            if(str[i]=='/n')
                break;
            if(str[i]==a||str[i]==a+32)
            cet++;
        }
    }
   else if(122>=a&&a>=97)
       {
        for(i=0;i<1000;i++)
    {   if(str[i]=='/n')
                break;
            if(str[i]==a||str[i]==a-32)
            cet++;
        }
    }
   else if((48<=a&&a<=57)||a==32)
              {
        for(i=0;i<1000;i++)
    {   if(str[i]=='/n')
                break;
            if(str[i]==a)
            cet++;
        }
    }

    printf("%d",cet);
}
全部评论

相关推荐

评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务