cin>>c && c!='?' 不AC嘞

#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    char c;
    int letter, digit, others;
    letter = digit = others = 0;
    while(cin>>c&&c!='?'){
        if((c<='z'&&c>='a')||(c<='Z'&&c>='A')) letter++;
        else if(c<='9' && c>='0') digit++;
        else others++;
    }
    cout<<"Letters="<<letter<<endl;
    cout<<"Digits="<<digit<<endl;
    cout<<"Others="<<others<<endl;
    return 0;
}
请问以上代码咋不通过嘞?
while(cin>>c&&c!='?') 和
while((c=getchar())!='?') 有啥差别吗
全部评论
#include<bits/stdc++.h> using namespace std; int main() { string s; getline(cin,s); int f1=0,f2=0; for(int i=0;i<s.size()-1;i++) { if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')) f1++; else if(s[i]>='0'&&s[i]<='9') f2++; } cout<<"Letters="<<f1<<endl; cout<<"Digits="<<f2<<endl; cout<<"Others="<<s.size()-1-f1-f2<<endl; return 0; }
点赞 回复 分享
发布于 2020-03-18 10:39
cin不读回车空格之类的字符
点赞 回复 分享
发布于 2020-03-13 11:11

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司6个岗位
点赞 评论 收藏
分享
活泼的代码渣渣在泡池...:哈哈哈挺好的,我也上岸美团了,不说了,我又接了一单
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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