当前位置:   article > 正文

24.1.24 DAY1 C++

24.1.24 DAY1 C++

思维导图

1.

提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数,要求使用C++风格字符串完成

代码:

  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4. int main()
  5. {
  6. int big=0;
  7. int small=0;
  8. int num=0;
  9. int space=0;
  10. int other=0;
  11. //string a="";
  12. string a;
  13. cout << "请输入字符串" << endl;
  14. getline(cin,a);
  15. cout << a <<endl;
  16. int i=a.size();
  17. cout << i << endl;
  18. for(i=a.size();i>0;i--)
  19. {
  20. if(a[i-1]==' ')
  21. space++;
  22. else if(a[i-1]<='9'&&a[i-1]>='0')
  23. num++;
  24. else if(a[i-1]<='Z'&&a[i-1]>='A')
  25. big++;
  26. else if(a[i-1]<='z'&&a[i-1]>='a')
  27. small++;
  28. else
  29. other++;
  30. }
  31. cout << "空格数量为" << space <<endl;
  32. cout << "数字数量为" << num <<endl;
  33. cout << "大写字母数量为" << big <<endl;
  34. cout << "小写字母数量为" << small <<endl;
  35. cout << "其他字符数量为" << other <<endl;
  36. return 0;
  37. }

运行结果:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/42297
推荐阅读
相关标签
  

闽ICP备14008679号