当前位置:秒懂百科馆 >

学前教育

> 怎样统计字符串中各字母的个数

怎样统计字符串中各字母的个数

怎样统计字符串中各字母的个数
这个有点困难哦,主要是问题很简单啦.要case 26次就行了.想了一下,要CASE来解决的话,要26个大写与26个小写,共52个CASE.下面是用指针来操作,在VC6里面测试可以通过.#include#include #include const int N=50;void main(){ char array[N],*p; int i,letter[52]={0},*pw;//52个存储大写与小写字母 cout<<"Input a string:"<='a'&&*p<='z') (*(pw+*p-'a'))++; else if(*p>='A'&&*p<='Z') (*(pw+26+*p-'A'))++; for(i=0;i<52;i++)//这里输出letter[0]-letter[51],大于零个的就输出 if(i<26&&letter[i]>0) cout<<"small letter: "<0) cout<<"strong letter: "<
  • 文章版权属于文章作者所有,转载请注明 https://mdbkg.com/xue/yoe40.html