题意描述

给你一个字符串,求所有字符的总数。

字符只包含数字,大小写字母。

分析

字符串的长度还是\(\le5\)的。

直接枚举就可以了。

AC代码:

NOIP官方标准程序是这样的
#include <iostream>
#include <cstdlib>
#include <string> int main() {
freopen("title.in", "r", stdin);
freopen("title.out", "w", stdout); std::string s;
std::getline(std::cin, s);
int cnt = 0;
if (s.length() > 0 && s[0] != ' ') ++cnt;
if (s.length() > 1 && s[1] != ' ') ++cnt;
if (s.length() > 2 && s[2] != ' ') ++cnt;
if (s.length() > 3 && s[3] != ' ') ++cnt;
if (s.length() > 4 && s[4] != ' ') ++cnt;
std::cout << cnt << std::endl; return 0;
}

直接枚举\(5\)个位。

还是我的比较可观:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring> using namespace std; char s[10];
int main() {
gets(s);//读入字符串(不推荐用,再Linux下的换行符和Windows下的不一样)
int ans=0;//清空ans
for (int i=0; i<strlen(s); i++) {//别忘了C++字符串下标是从0开始的
if (s[i]>='A' &&s[i]<='Z') ans++;
if (s[i]>='a' &&s[i]<='z') ans++;
if (s[i]>='0' &&s[i]<='9') ans++;//数字
}
printf("%d\n",ans);//输出结果
return 0;
}

最新文章

  1. 022 UFT虚拟对象
  2. python basic programs
  3. Eclipse安装ADT失败解决办法
  4. Linux IPC(Inter-Process Communication,进程间通信)之管道学习
  5. 用java理解程序逻辑小结
  6. PageRank之基于C C#的基本实现
  7. Mac下显示隐藏的文件
  8. Django+Bootstrap+Mysql 搭建个人博客(三)
  9. idea 快键键
  10. ERROR: Field * doesn&#39;t have a default value
  11. Jenkins小试
  12. 查看Selinux和关闭Selinux
  13. HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP错误解决方法
  14. 新建maven web 项目后,出现的小问题
  15. C/C++的Name Mangling
  16. SpringMvc注解开发
  17. [javaSE] 数组(获取最值)
  18. 造成MySQL全表扫描的原因
  19. Android调试大法 自定义IDE默认签名文件==&gt;微信支付、微信登录、微信分享,debug时调试通过,release时调不起微信
  20. C语言——无向带权图邻接矩阵的建立

热门文章

  1. HTML5存储--离线存储
  2. 两种高效的事件处理模型:Reactor模式和Proactor模式
  3. 模拟telnet协议C语言客户端程序
  4. POWERSPLOIT-Exfiltration(信息收集)脚本渗透实战
  5. socat的介绍与使用
  6. C# 结合 Golang 开发
  7. win10系统plsql卡顿、菜单闪烁解决办法
  8. 常用函数-Win-IP
  9. Swoole 实现在线聊天
  10. django1-环境搭建