为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

字符串str,、数字、空格以及其他字符出现的次数

2017-12-20 4页 doc 14KB 8阅读

用户头像

is_036899

暂无简介

举报
字符串str,、数字、空格以及其他字符出现的次数字符串str,、数字、空格以及其他字符出现的次数 指针 #include #include /*统计函数*/ void check(char *str) { int i,number=0,space=0,zimu=0,other=0; char *p=str; for(i=0;i='0' && *(p+i)='a' && *(p+i)='A' && *(p+i) #include using namespace std; inline int str_len(char *p) { { if(p==...
字符串str,、数字、空格以及其他字符出现的次数
字符串str,、数字、空格以及其他字符出现的次数 指针 #include #include /*统计函数*/ void check(char *str) { int i,number=0,space=0,zimu=0,other=0; char *p=str; for(i=0;i='0' && *(p+i)<='9') /*数字*/ number++; else if(*(p+i) == 32) /*空格*/ space++; else if((*(p+i)>='a' && *(p+i)<='z')||(*(p+i)>='A' && *(p+i)<='Z')) zimu++;/*其它字符*/ else other++; } printf("%s\n",str); printf("number:%d\nspace:%d\nzimu:%d\nother char:%d\n",number,space,zimu,other); } /*主函数*/ main() { char string[100]; gets(string); /*输入字符串,因为要包括空格,不能用scanf()*/ check(string); /*调用函数*/ } 引用 #include #include using namespace std; inline int str_len(char *p) { { if(p==NULL) return 0; int n=0; char *q=p; while(*q!='\0') { n++; q++; } return n; } } void tongji(char *st,int n,int &zimu,int &shuzi,int &kongge,int &other) { char str; for(int i=0;i='A'||str<='z'&&str>='a') zimu+=1; else if(str<='9'&&str>='0') shuzi+=1; else if(str==' ') kongge+=1; else other+=1; } } int main(int argc, char *argv[]) { char s[1000]; int zimu=0,shuzi=0,kongge=0,other=0,n; cout<<"请输入一个字符串:"; cin>>s; n=str_len(s); tongji(s,n,zimu,shuzi,kongge,other); cout<<"统计结果如下:"<
/
本文档为【字符串str,、数字、空格以及其他字符出现的次数】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索