题解 | #统计字符#

统计字符

http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    while(getline(cin, str))
    {
        int length = str.length();
        int iLetter=0,iSpace=0,iNum=0,iOther=0;
        for(int i=0; i<length; i++)
        {

           if(str[i]-'a'>=0 && str[i]-'z'<=0)
           {
               iLetter ++;
           }
           else if(str[i]-'0'>=0 && str[i]-'9'<=0)
           {
               iNum ++;
           }
           else if(str[i]-' '==0)
           {
               iSpace ++;
           }
           else
           {
               iOther ++;
           }
        }
        cout<<iLetter<<endl<<iSpace<<endl<<iNum<<endl<<iOther<<endl;
    }
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 11:31
点赞 评论 收藏
分享
点赞 评论 收藏
分享
程序员小白条:太晚了,看别人找到实习了才投的话,自己本身就没啥准备,计划太晚咯,只能吞苦果子
点赞 评论 收藏
分享
评论
6
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务