题解 | #字符统计#

金字塔

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

using namespace std;
#define int long long
#define endl '\n'
signed main(){
    std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   char s;
    int letter=0,digits=0,other=0;
    while(cin.get(s)&&s!='?'){//用cin.get是处理空格也是一个字符,用cin不能算空格是字符。如果用s=getchar()会运行超时,不过把getchar写在循环下面就不会超时了    
        if((s>='a'&&s<='z')||(s>='A'&&s<='Z'))letter++;
        else if(s>='0'&&s<='9')digits++;
        else other++;
    }
    cout<<"Letters="<<letter<<endl;
    cout<<"Digits="<<digits<<endl;
    cout<<"Others="<<other<<endl;
    return 0;
}
全部评论

相关推荐

2025-12-22 16:31
已编辑
桂林电子科技大学 Python
很奥的前端仔:如果你接了offer 临时又说不去 hr确实要多做一些工作。 当然如果是接offer之前当我没说
点赞 评论 收藏
分享
哈哈哈,你是老六:我去,这面试还要靠抢啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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