C++:统计字符串内大小写字母,数字空格,逗号等
发布日期:2021-06-29 14:38:15 浏览次数:2 分类:技术文章

本文共 974 字,大约阅读时间需要 3 分钟。

川川好久没发文了,最近实在太忙,要是感兴趣可以直接跟我私聊, QQ:2835809579

原题:

用赋初值的方法把字符串 “ C is a general purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.” 存放到字符数组s中,编程统计其中的大写字母、小写字母、数字、空格、逗号的个数。

代码:

#include
using namespace std;int main(){
char c; int smallletters = 0, largeletters=0,space = 0, digit = 0,douhao=0, other = 0; cout << "请输入字符串:"; while ((c = getchar()) != '\n') {
if (c >= 'a' && c <= 'z') {
smallletters++; } else if (c >= 'A' && c <= 'Z') {
largeletters++; } else if (c == ' ') {
space++; } else if (c >= '0' && c <= '9') {
digit++; } else if (c == ',') {
douhao++; } else {
other++; } } cout <<"小写字母:"<< smallletters <<"\t"<<"大写字母:"<
<<"\t"<<"空格:"<< space <<"\t"<<"数字:"<< digit <<"\t"<<"逗号:"<
<<"\t"<<"其它:"<< other <<"\t"<< endl; return 0;}

有问题,留言或者加我扣扣问我吧。

转载地址:https://chuanchuan.blog.csdn.net/article/details/110931372 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C++:10以内的累加
下一篇:C语言: 定义一个函数int isprime(int n),用来判别一个正整数n是否为素数。在主函数中输入两个正整数m和n(m>=1,n>m),统计并输出m和n之间的素数的个数以及这些素数的和。

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月23日 13时15分17秒