华为-输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数

网友投稿 985 2022-10-03

华为-输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数

华为-输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数

题目链接

​​     * 统计出英文字母字符的个数。      *       * @param str 需要输入的字符串      * @return 英文字母的个数      */     public static int getEnglishCharCount(String str)     {         return 0;     }          /**      * 统计出空格字符的个数。      *       * @param str 需要输入的字符串      * @return 空格的个数      */     public static int getBlankCharCount(String str)     {         return 0;     }          /**      * 统计出数字字符的个数。      *       * @param str 需要输入的字符串      * @return 英文字母的个数      */     public static int getNumberCharCount(String str)     {         return 0;     }          /**      * 统计出其它字符的个数。      *       * @param str 需要输入的字符串      * @return 英文字母的个数      */     public static int getOtherCharCount(String str)     {         return 0;     }

输入描述:

输入一行字符串,可以有空格

输出描述:

统计其中英文字符,空格字符,数字字符,其他字符的个数

示例1

输入

复制

1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\\/;p0-=\\][

输出

复制

2631012

题解:

#include #include using namespace std;int main(){ string s; while (getline(cin, s)){ int num_eng = 0, num_space = 0, num_num = 0, num_else = 0; for (int i = 0; i < s.length(); i++){ if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')){ num_eng++; } else if (s[i] >= '0' && s[i] <= '9'){ num_num++; } else if (s[i] == ' '){ num_space++; } else{ num_else++; } } cout << num_eng << endl << num_space << endl << num_num << endl << num_else << endl; } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:LeetCode-224. Basic Calculator
下一篇:微信小程序怎么引入模板(微信小程序引入模板导致原网页失效)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~