武汉科技大学ACM :1003: 零起点学算法67——统计字母数字等个数
Problem Description
输入一串字符,统计这串字符里的字母个数,数字个数,空格字数以及其他字符(最多不超过100个字符)
Input
多组测试数据,每行一组
Output
每组输出一行,分别是字母个数,数字个数,空格字数以及其他字符个数
Sample Input
I am a student in class 1.
I think I can!
Sample Output
18 1 6 1
10 0 3 1
HINT
char str[100];//定义字符型数组
while(gets(str)!=NULL)//多组数据
{
//输入代码
for(i=0;str[i]!='\0';i++)//gets函数自动在str后面添加'\0'作为结束标志
{
//输入代码
}
//字符常量的表示,
'a'表示字符a;
'0'表示字符0;
//字符的赋值
str[i]='a';//表示将字符a赋值给str[i]
str[i]='0';//表示将字符0赋值给str[i]
}
我的代码:
#include<stdio.h>
int main()
{
char ch[];
while(gets(ch)!=NULL) {
int char_num=,kongge_num=,int_num=,other_num=,i;
for(i=;ch[i]!='\0';i++) {
if(ch[i]>='A' && ch[i]<='Z' || ch[i]<='z' && ch[i]>='a')
{
char_num++;
}
else if(ch[i]==' ')
{
kongge_num++;
}
else if(ch[i]>=''&&ch[i]<='')
{
int_num++;
}
else
{
other_num++;
}
}
printf("%d %d %d %d\n",char_num,int_num,kongge_num,other_num);
}
return ;
}
其他代码:
#include<stdio.h>
#include<string.h>
int main()
{
char str[];//定义字符型数组
int a=, b=, c=, d=;//字母,数字,空格,和其它
while (gets(str) != NULL){
int length = strlen(str);
for (int i = ; i < length; i++){
if (str[i] >= 'A'&&str[i] <= 'Z'||str[i] >= 'a'&&str[i] <= 'z'){
a++;
}
else if (str[i] == ' '){
c++;
}
else if (str[i] >= ''&&str[i] <= ''){
b++;
}
else{
d++;
}
}
printf("%d %d %d %d\n", a, b, c, d);
a=; b=; c=; d=;
}
return ;
}
#include <iostream>
#include<cctype>
using namespace std; char s[];
int main()
{
int alpha,num,space,other;
while(gets(s))
{
alpha=,num=,space=,other=;
for(int i=;s[i]!='\0';++i)
{
if(isalpha(s[i])) ++alpha;
else if(isdigit(s[i])) ++num;
else if(s[i]==) ++space;
else ++other;
}
cout<<alpha<<" "<<num<<" "<<space<<" "<<other<<endl;
}
return ;
}
武汉科技大学ACM :1003: 零起点学算法67——统计字母数字等个数的更多相关文章
- Problem F: 零起点学算法101——统计字母数字等个数
#include<stdio.h> #include<string.h> int main(){ ]; while(gets(str)!=NULL){ ,b=,c=,d=; ; ...
- WUOJ-ACM :1003: 零起点学算法78——牛牛
武汉科技大学ACM :1003: 零起点学算法78--牛牛Problem Description牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中 ...
- 武汉科技大学ACM :1003: 零起点学算法78——牛牛
Problem Description 牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中3张牌的点数之和是10的倍数,则为有牛,剩下两张牌的点数 ...
- 武汉科技大学ACM :1003: 零起点学算法14——三位数反转
Problem Description 水题 Input 输入1个3位数(题目包含多组测试数据) Output 分离该3位数的百位.十位和个位,反转后输出(每组测试数据一行) Sample Input ...
- Problem G: 零起点学算法106——首字母变大写
#include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...
- Problem K: 零起点学算法107——统计元音
#include<stdio.h> int main() { int n; ]; while(scanf("%d%*c",&n)!=EOF) { while(n ...
- Problem F: 零起点学算法85——数组中插入一个数
#include<stdio.h> int main() { ],b[]; while(scanf("%d",&n)!=EOF) { ;i<n;i++) ...
- 1163: 零起点学算法70——Yes,I can!
1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1164: 零起点学算法71——C语言合法标识符(存在问题)
1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 10 ...
随机推荐
- Sql Server索引(转载)
官方说法: 聚集索引 一种索引,该索引中键值的逻辑顺序决定了表中相应行的物理顺序. 聚集索引确定表中数据的物理顺序.聚集索引类似于电话簿,后者按姓氏排列数据.由于聚集索引规定数据在表中的物理存储顺序, ...
- 1104解决ecos挂件中数组传递的相关问题。
1.挂件综述: 挂件组成:_config.html 后台配置,即点添加时的弹出框. default.html 前台显示,即在前台显示出来的页面. widget.php 设置挂件的基本信息.. ...
- Symfony2目录结构说明
了解框架的目录结构是框架快速入门的一个途径,一个成熟的框架,每个功能模块都被划分存放在不同的目录. Symfony2一级目录结构: ├── app //这目录下包含了,配置文件(应用的配置文件会被im ...
- mysql_config not found
在python中安装MySQL_python.不想通过下载源码编译,而是想用 easy_install MySQL_python 来安装.结果一直报错: mysql_config not found ...
- mysql优化 - mysql 的 hint
FORCE INDEX 强制索引 只使用建立在field1上的索引,而不使用其它字段上的索引. SELECT * FROM table1 FORCE INDEX (field1) IGNORE IND ...
- vue访问原生 DOM 事件
<body> <div id="test"> <button @click="changeColor('你好',$event)"& ...
- Spark Streaming 数据接收过程
SparkStreaming 源码分析 一节中从源码角度,描述了Streaming执行时代码的调用过程.下边就接收转化阶段过程再简单分析一下,为分析backpressure作准备. SparkStre ...
- Android 之 AlertDialog 用户登录
1:activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- Ubuntu 下启动/停止/重启mysql服务
1:sudo start mysql 2:sudo stop mysql 3:sudo restart mysql
- uva 10020 Minimal coverage
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...