功能:利用指针统计一个字符串中,字母、空格、数字、及其它字符的个数。
答案:1 悬赏:30 手机版
解决时间 2021-02-28 18:51
- 提问者网友:蓝莓格格巫
- 2021-02-27 18:38
功能:利用指针统计一个字符串中,字母、空格、数字、及其它字符的个数。
最佳答案
- 五星知识达人网友:动情书生
- 2021-02-27 19:38
#include "stdafx.h"
#include <iostream>
#include "windows.h"
using namespace std;
void getSize(char* p){
int space = 0;
int Number = 0;
int letter = 0;
int other = 0;
for(;*p!='\0';p++) {
if((*p>='a' && *p<='z') || (*p>='A' && *p<='Z'))letter++;
else if(*p==' ')space++;
else if(*p>='0' && *p<='9')Number++;
else other++;
}
cout<<"space:"<<space<<"Number:"<<Number<<"letter:"<<letter<<"other:"<<other<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
getSize("abcd 567");//请输入你要测试的字符串
system("pause");
return 0;
}
#include <iostream>
#include "windows.h"
using namespace std;
void getSize(char* p){
int space = 0;
int Number = 0;
int letter = 0;
int other = 0;
for(;*p!='\0';p++) {
if((*p>='a' && *p<='z') || (*p>='A' && *p<='Z'))letter++;
else if(*p==' ')space++;
else if(*p>='0' && *p<='9')Number++;
else other++;
}
cout<<"space:"<<space<<"Number:"<<Number<<"letter:"<<letter<<"other:"<<other<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
getSize("abcd 567");//请输入你要测试的字符串
system("pause");
return 0;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯