题解 | #abc#

统计字符串中各类型字符的个数

http://www.nowcoder.com/practice/d5b44c494ed24d8ebb10607c469280e3

#include #include using namespace std;

int main() {

int letter = 0;
int digit = 0;
int space = 0;
int other = 0;

char buf[1024] = {0};
cin.getline(buf, sizeof(buf));

// write your code here......
char *p;
for(p=buf;*p!='\0';p++){
    if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z'))
        letter++;
    else if(*p>='0'&&*p<='9')
        digit++;
    else if(*p==' ')
        space++;
    else
        other++;
}

cout << "letter:" << letter << " digit:" << digit << " space:" << space << " other:" << other << endl;

return 0;

}

全部评论

相关推荐

04-13 09:56
已编辑
嵌入式工程师
点赞 评论 收藏
分享
牛客29046817...:优化一下简历,突出重点,简历上的技能复习扎实,实习工作啥的整理成文档梳理一下怎么说要有自己的思考在里边,岗位的话运维,测试,开发,实施,技术支持能投的都投,多投递能找到的,秋招投递了3个月左右(8月中旬到11月下旬),boos打招呼8000多次,官网投递300多家,才找到一家满意的
点赞 评论 收藏
分享
好羡慕走AI技术方向的人,实习薪资这么高😱&nbsp;人比人气死人😭
勇敢的嘟教授在考古:芯片公司挣得多多的,钱给的还不如互联网
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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