第十五周oj训练——统计字符串种类(2569)
2016-12-10 20:37
176 查看
问题及代码
主函数已经给出,请编写统计字符种类函数。
Description
用指针编写一个程序,输入字符串后,统计其中各种字符的个数,输出其中大小写字母,数字,以及其他字符的个数。主函数已经给出,请编写统计字符种类函数。
Input
一串字符串Output
该字符串中大小写字母,数字,以及其他字符的个数,最后输出总字符串长度。Sample Input
I play LOL for 3 years.
Sample Output
4 12 1 6 23
/*烟台大学计算机学院 2016 作者: 马春澎 完成日期:2016年12月10日 */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char str[100]; gets(str); char *ptr=str; void fuction(char *); fuction(ptr); return 0; } void fuction(char *p) { int i,n,a,b,c,d; a=b=c=d=0; n=strlen(p); for(i=0; i<n; i++) { if((p[i]>='A')&&(p[i]<='Z')) a++; if((p[i]>='a')&&(p[i]<='z')) b++; if((p[i]>='0')&&(p[i]<='9')) c++; } d=n-a-b-c; printf("%d\n%d\n%d\n%d\n%d",a,b,c,d,n); }
运算结果
知识点总结
字符串和函数的应用
学习心得
练得多了就会有很大的进步!
相关文章推荐
- Install OpenCV 3.0 and Python 2.7+ on Ubuntu
- Java正则表达式规则
- 【UWP】列表项宽度自适应的实现
- LeetCode41. First Missing Positive
- 将SHP导入MySQL中
- spring注解详解
- xml解析,dom/sax
- c/c++编程题 之 验证哥德巴赫猜想
- 今天我得到了一台计算机
- 我的近期学习计划
- POJ 3469:Dual Core CPU (最大流)
- CentOS6.8启动报错:Could not update ICEauthority file /var/lib/gdm/.ICEauthority
- hdu 5805 D - NanoApe Loves Sequence 记录最大值dp
- C_0327_02 hellowword记事本编程
- 嵌入式Linux开发环境搭建
- 13、(知识篇)Spring使用xml配置bean02
- c/c++编程题 之 求sin(x)近似值
- 帕累托分布图--python学习笔记18
- Sqlite数据库管理(SQLite Developer) v4.0.0.528 中文版+破解方法(申明:来源于网络)
- python内置数据结构