第九周OJ1统计出其中英文字母、数字、空格和其他字符的个数
2016-10-27 09:02
288 查看
问题及代码
运行结果
知识点总结
字符型数据使用
利用循环结构进行统计
学习心得
一开始使用的scanf()!=EOF并没有输出结果,之后改成getchar()!=‘\n’程序才可以输出结果。
/* 烟台大学计算机与控制工程学院 文件名称: 统计出其中英文字母、数字、空格和其他字符的个数 作 者:展一 完成时间:2016年10月27日 题目描述 输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。 输入 一行字符 输出 统计值 样例输入 aklsjflj123 sadf918u324 asdf91u32oasdf/.';123 样例输出 23 16 2 4 */ #include <stdio.h> #include <stdlib.h> int main() { int letter=0,number=0,space=0,other=0; char x; while((x=getchar())!='\n') { if((x>='a'&&x<='z')||(x>='A'&&x<='Z')) letter++; else if(x>='0'&&x<='9') number++; else if(x==' ') space++; else other++; } printf("%d %d %d %d\n",letter,number,space,other); return 0; }
运行结果
知识点总结
字符型数据使用
利用循环结构进行统计
学习心得
一开始使用的scanf()!=EOF并没有输出结果,之后改成getchar()!=‘\n’程序才可以输出结果。
相关文章推荐
- 第九周OJ项目-统计出其中英文字母、数字、空格和其他字符的个数
- 第九周OJ总结<1>-统计出其中英文字母、数字、空格和其他字符的个数
- oj第九周练习 统计出其中英文字母、数字、空格和其他字符的个数
- OJ刷题之统计出其中英文字母,数字,空格和其他字符的个数
- OJ刷题之《统计出其中英文字母、数字、空格和其他字符的个数》
- 第九周-统计出其中英文字母、数字、空格和其他字符的个数
- 华为oj_输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 第九周练习--统计出其中英文字母、数字、空格和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数。
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- [c++]输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。(写的代码有疑惑,求解求教)
- 输入一行字符,分别统计出其中英文字母 空格 数字和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数
- 统计出其中英文字母、数字、空格和其他字符的个数
- 输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数【while循环】
- 统计出其中英文字母、数字、空格和其他字符的个数
- [YTU]_1032( 统计出其中英文字母、数字、空格和其他字符的个数)
- 作业3-3 输入 15 个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数
- 50道编程题之07:输入一行字符,分别统计出其中的英文字母,空格,数字和其他字符的个数