题解 | #统计大写字母个数#

统计大写字母个数

http://www.nowcoder.com/practice/434414efe5ea48e5b06ebf2b35434a9c

思路

  1. 获得输入的字符串,因为包含空格等其他字符,所以用gets()
  2. 统计A-Z的字符个数
  3. 输出字符个数

Answer

#include<stdio.h>
#include<string.h>

int main()
{
    char str[256];
    int cnt=0;
    gets(str);
    for(int i=0;i<strlen(str);i++){
        if(str[i]>='A' && str[i]<='Z'){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}
全部评论

相关推荐

2024-12-23 06:50
门头沟学院 Java
给点吧求求了:3点发的帖子,害怕😰
点赞 评论 收藏
分享
EEbond:给北邮✌️跪了
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务