第13周项目 5.1 字符串操作

来源:互联网 发布:ae软件下载 编辑:程序博客网 时间:2024/05/16 15:19

/*

     *   copyright     (c)   2014   ,    烟台大学计算机学院

     *   all  rights   reserved  .

     *   文件名称   :    textst  .    cpp

     *    作者  :    孙旭明

     *     完成日期    :    2014年12月8日

     *     版本号    :     v1.0

     *

     *    问题描述    :   

     *     程序输出    :      

     */ #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    char str[50];  //定义一个可以接受50个字符的数组
    int i=0,n=0;
    cout<<"输入字符串:"<<endl;;
    gets(str);
    while(str[i]!='\0')
    {
        if(str[i]=='A')
        {
            n++;
        }
        i++;
    }
    cout<<"其中的字母“A”出现的次数是: "<<n<<endl;
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
   char str[50];  //定义一个可以接受50个字符的数组
   int i,m,n;
    i=m=n=0;
    cout<<"输入字符串:"<<endl;;
    gets(str);
    while(str[i]!='\0')
    {
        if(str[i]>='A'&&str[i]<='Z')  //统计字符串中大写字母的个数
        {
            m++;
        }
        if(str[i]>='a'&&str[i]<='z')  //统计字符串中小写字母的个数
        {
            n++;
        }
        i++;
    }
    cout<<"字符串中大写字母的个数是: "<<m<<endl;
    cout<<"字符串中小写字母的个数是: "<<n<<endl;
    return 0;
}




0 0
原创粉丝点击