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

计算某字符出现次数

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

#include<stdio.h>
#include<string.h>

int search(char str[],int Size,char word)
{
	int i=0;
	int count=0;
	if(('a'<=word&&word<='z')||('A'<=word&&word<='Z'))
	{
	   
		for(i=0;i<Size;i++)
			{
				if(('a'-1)<str[i]<='z'||('A'-1)<str[i]<='Z')
				{
					if(str[i]==word||(str[i]-32)==word||(str[i]+32)==word)
						{
							count++;
						}
				}
	
			}
	}
	else {
	
		for(i=0;i<Size;i++)
			{
		     	if(str[i]==word)
		     	{
		     		count++;
		     	
				}
			}
	}
	return count;
}
int main()
{
	char str[2048];
	char a;
	fgets(str,2048,stdin);
	scanf("%c",&a);
	printf("%d",search(str,strlen(str)-1,a));

    return 0;
}

全部评论

相关推荐

最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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