小黑鱼王


私信TA

用户名:WangSC

访问量:3081

签 名:

等  级
排  名 6423
经  验 1357
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校 华北水利水电大学
专  业

  自我简介:

解题思路:

要是想要写这个代码需要知道的几点:

1、gets()可以输入字符串,其头文件为#include <cstring>

2、isdigit(str(i))和isalpha(str(i))分别可以判断字符串里的数字和字母

3、空格的ASCII码是32

4、一些基本的编码规范

注意事项:

很简单的一道题,想要自己做出来还是需要多加练习

参考代码:

#include <iostream>

#include <cstdio>

#include <cstring>

using namespace std;


int main ()

{

char str[100];

int alpha=0,digit=0,space=0,other=0;

int n=100;

gets(str); //字符串的输入 

for(int i=0;i<strlen(str);i++)

{

if (isalpha(str[i]))

++alpha;

else if(isdigit(str[i]))

++digit;

else if(str[i]==32)

++space;

else

++other;

}

cout<<alpha<<" "<<digit<<" "<<space<<" "<<other<<endl;

return 0;

 } 


 

0.0分

10 人评分

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

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

我最开始用cin而不是gets,cin输入好像识别到了空格就停止了,大佬能不能解释一下原因?
2021-02-22 21:40:18
  • «
  • 1
  • »