题解 | #字符统计#

字符统计

https://ac.nowcoder.com/acm/problem/22202

输入流get函数获取每个字符进行判断
#include<iostream>
using namespace std;
int main(){
    int letters=0,digits=0,other=0;
    char ch;
    ch=cin.get();
    while(ch!='?'){
        if((ch>=65&&ch<=90)||(ch>=97&&ch<=122)) letters++;
        else if(ch>=48&&ch<=57) digits++;
        else other++;
        ch=cin.get();
    }
    cout<<"Letters="<<letters<<endl<<"Digits="<<digits<<endl<<"Others="<<other;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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