题解 | #统计字符#

统计字符

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

#include <string.h>
#include <iostream>
using namespace std;
int main()
{
    string a;
    while(getline(cin,a))
    {
        int b[4]={0};
        int c=a.length();
        for(int i=0;i<c;i++)
        {
            if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
            {
                b[0]=b[0]+1;
                continue;
            }
            else if(a[i]==' ')
            {
                b[1]=b[1]+1;
                continue;
            }
            else if(a[i]>='0'&&a[i]<='9')
            {
                b[2]=b[2]+1;
                continue;
            }
            else
            {
                b[3]=b[3]+1;
            }
        }
        for(int i=0;i<=3;i++)
        {
            cout<<b[i]<<'\n';
        }
    }
    return(0);
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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