首页 > 编程语言 > 详细

2. C++ 统计字符串中英文字母、空格、数字和其它字符的个数

时间:2021-06-10 12:27:52      阅读:32      评论:0      收藏:0      [点我收藏+]
输入一行字符,分别统计其中字母、空格、数字和其他字符的个数。
1
// 2 // Created by Green on 2021/6/9. 3 // 4 #include <iostream> 5 6 using namespace std; 7 int letters, digit, space, others; 8 9 int main(void) { 10 cout << "please input some characters" << endl; 11 int c; 12 while ((c = getchar()) != \n) { 13 if (c >= a && c <= z || c >= A && c <= Z) { 14 letters++; 15 } else if (c == 32) { 16 space++; 17 } else if (c >= 0 && c <= 9) { 18 digit++; 19 } else { 20 others++; 21 } 22 } 23 cout << "letters: " << letters << endl 24 << "digit: " << digit << endl 25 << "space: " << space << endl 26 << "others: " << others << endl; 27 return 0; 28 }

 

2. C++ 统计字符串中英文字母、空格、数字和其它字符的个数

原文:https://www.cnblogs.com/yj2434/p/14869436.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!