字符串操作(2)

来源:互联网 发布:丹东917事件知乎 编辑:程序博客网 时间:2024/06/01 10:45

问题及代码:

/** Copyright (c) 2014, 烟台大学计算机学院* All rights reserved.* 文件名称:test.cpp* 作    者:夏焕哲* 完成日期:2014 年 11  月  20  日* 版 本 号:v1.0** 问题描述:字符串操作。* 输入描述: 统计字符串中大小写分别出现的次数。* 程序输出: 输出字母大小写分别出现出现的个数。*/#include<iostream>#include<cstdio>using namespace std;int main(){    char str[50];    int i=0,up=0,low=0;    cout<<"输入字符串:";    gets(str);    while(str[i]!='\0')    {        if(str[i]>='A'&&str[i]<='Z')            up++;        else if(str[i]>='a'&&str[i]<='z')            low++;        i++;    }    cout<<"其中大写字母出现的次数是: "<<up<<endl;    cout<<"其中小写字母出现的次数是:"<<low<<endl;    return 0;}


运行结果:

0 0