华为历年笔试面试机考试题在线练习----计算字符个数

xiaoxiao2021-02-28  42

题目描述

写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

输入描述: 输入一个有字母和数字以及空格组成的字符串,和一个字符。

输出描述: 输出输入字符串中含有该字符的个数。

示例1

输入

ABCDEF A

输出

1 #include<stdio.h> #include<string.h> int main(){ char str[1024]; gets(str); char s; scanf("%c",&s); int count = 0; int len; len = strlen(str); int i = 0; for(; i < len; i ++){ if(str[i] == s ||str[i]+32== s || str[i]-32 == s) count ++; } printf("%d",count); }

转载请注明原文地址: https://www.6miu.com/read-2626307.html

最新回复(0)