Chiro


私信TA

用户名:21000916Chiro

访问量:708

签 名:

下面有人拿快排过堆排的题,我不(9)说(1)是(5)谁

等  级
排  名 4633
经  验 1602
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校 广东工业大学
专  业

  自我简介:

TA的其他文章

母牛的故事
浏览:99

解题思路:

利用cctype字符函数库解决问题

cctype库内函数

isalnum(c); 如果参数是字母或数字,函数就返回true,否则返回false

isalpha(c); 如果参数是字母,函数返回true, 否则返回false

islower(c); 如果参数是小写字母,函数返回true

isupper(c); 如果参数是大写字母,函数返回true

isdigit(c); 如果参数是数字,函数返回true

isxdigit(c); 如果参数是十六进制数字,即0 ~ 9,a ~ f或A ~ F,函数返回true

ispunct(c); 如果参数是标点符号,函数返回true

iscntrl(c); 如果参数是控制字符,函数返回true

isgraph(c); 如果参数除空格之外的打印字符,函数返回true

isprint(c); 如果参数是打印字符(包括空格' '),函数返回true

注意事项:

循环的判断条件,头文件#include<cctype>
参考代码:

#include<iostream>

#include<cctype>

using namespace std;

int main()

{

char ch;

int digits =0, chars=0 ,whitespace=0 ,others=0 ;

cin.get(ch);

while (ch!='\n') {

if (isalpha(ch)) {

chars++;

}

else if (isdigit(ch)) {

digits++;

}

else if (isspace(ch)) {

whitespace++;

}

else {

others++;

}

cin.get(ch);

}

cout << chars << " " << digits << " " << whitespace << " " << others;

return 0;

}


 

0.0分

3 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区