[YTU]_1055 (输入字符串以及输出)
来源:互联网 发布:西班牙语 知乎 编辑:程序博客网 时间:2024/06/08 01:08
Description
编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
Input
一行字符串
Output
统计数据,4个数字,空格分开。
Sample Input
!@#$%^QWERT 1234567
Sample Output
5 7 4 6
编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
Input
一行字符串
Output
统计数据,4个数字,空格分开。
Sample Input
!@#$%^QWERT 1234567
Sample Output
5 7 4 6
#include <iostream>using namespace std;void tongji(char*p,int *q){(*(q+3))=(*(q+2))=(*(q+1))=*q=0; for(;*p!='\0';p++) { if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z')) (*q)++; else if(*p>=48&&*p<=57) (*(q+1))++; else if(*p==' ') (*(q+2))++; else (*(q+3))++; }}int main(){ char str[100]; int i,a[4]={0}; cin.getline(str,99); tongji(str,a); for(i=0; i<4; i++) cout<<a[i]<<" "; cout<<endl; return 0;}
#include <iostream>using namespace std;void tongji(char *p,int *aa){ int m=0,n=0,j=0,k=0; for(int i=0;*(p+i)!='\0';i++) { if((*(p+i)>='a'&&*(p+i)<='z')||(*(p+i)>='A'&&*(p+i)<='Z')) { m++; *aa=m; } else if(*(p+i)>='0'&&*(p+i)<='9') { n++; aa[1]=n; } else if(*(p+i)==' ') { j++; aa[2]=j; } else {k++; aa[3]=k; } }}int main(){ char str[100]; int i,a[4]; cin.getline(str,99); tongji(str,a); for(i=0;i<4;i++) cout<<a[i]<<' '; cout<<endl; return 0;}
阅读全文
0 0
- [YTU]_1055 (输入字符串以及输出)
- ytu:输入字符串以及输出
- YTU 1055: 输入字符串以及输出
- 输入字符串以及输出
- 输入字符串以及输出
- 输入字符串以及输出
- 输入字符串以及输出
- [YTU]_1064 (输入三个字符串,按由小到大的顺序输出)
- Problem A: 输入字符串以及输出
- Problem A: 输入字符串以及输出
- Problem A: 输入字符串以及输出
- 问题 A: 输入字符串以及输出
- YTU-OJ- 对象数组输入与输出
- YTU:学生成绩输入和输出
- YTU 2432: C++习题 对象数组输入与输出
- YTU 2429: C语言习题 学生成绩输入和输出
- [YTU]_1046 ( 输入10个数字,然后逆序输出)
- [YTU]_2429( C语言习题 学生成绩输入和输出)
- Android玩 --- Material Design(1) --- Recycleview的装饰(2)
- C++高精度算法之比大小
- eclipse安装hibernate插件
- 【Quartz】 JobListener、Triggerlistener、SchedulerListener介绍与使用
- 一些建站过程的图片
- [YTU]_1055 (输入字符串以及输出)
- 算法 排序算法之时间复杂度和空间复杂度
- G
- 接下来的安排+U3D界面初探
- Android控件2
- 练习题讲解-【搜索算法】置棋问题
- UVA
- C++11智能指针之std::unique_ptr
- 【Quartz】Quartz存储与持久化-基于quartz.properties的配置