kkky


私信TA

用户名:20200702041

访问量:1324

签 名:

等  级
排  名 21320
经  验 644
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校 湖北中医药大学
专  业

  自我简介:

菜鸡的自我练习

解题思路:   字符数组接收,运用strlen函数得出数组长度,条件遍历计数得出结果

注意事项:       gets能读取空格  scanf不能读取空格

参考代码:

#include <iostream>

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int letter=0,number=0,blank=0,other=0;

   char str [200];

   gets(str);

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

  {

      if(str[i]>='0'&&str[i]<='9')

        number++;

        else if(str[i]>='A'&&str[i]<='Z')

            letter++;

        else

      if(str[i]>='a'&&str[i]<='z')

        letter++;

        else

      if(str[i]==' ')

        blank++;

      else

        other++;

  }

  cout<<letter<<" "<<number<<" "<<blank<<" "<<other;

    return 0;

}


 

0.0分

1 人评分

  评论区