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——统计字母数字等个数的更多相关文章

  1. Problem F: 零起点学算法101——统计字母数字等个数

    #include<stdio.h> #include<string.h> int main(){ ]; while(gets(str)!=NULL){ ,b=,c=,d=; ; ...

  2. WUOJ-ACM :1003: 零起点学算法78——牛牛

    武汉科技大学ACM :1003: 零起点学算法78--牛牛Problem Description牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中 ...

  3. 武汉科技大学ACM :1003: 零起点学算法78——牛牛

    Problem Description 牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中3张牌的点数之和是10的倍数,则为有牛,剩下两张牌的点数 ...

  4. 武汉科技大学ACM :1003: 零起点学算法14——三位数反转

    Problem Description 水题 Input 输入1个3位数(题目包含多组测试数据) Output 分离该3位数的百位.十位和个位,反转后输出(每组测试数据一行) Sample Input ...

  5. Problem G: 零起点学算法106——首字母变大写

    #include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...

  6. Problem K: 零起点学算法107——统计元音

    #include<stdio.h> int main() { int n; ]; while(scanf("%d%*c",&n)!=EOF) { while(n ...

  7. Problem F: 零起点学算法85——数组中插入一个数

    #include<stdio.h> int main() { ],b[]; while(scanf("%d",&n)!=EOF) { ;i<n;i++) ...

  8. 1163: 零起点学算法70——Yes,I can!

    1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: ...

  9. 1164: 零起点学算法71——C语言合法标识符(存在问题)

    1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 10 ...

随机推荐

  1. php 学习路线 赵兴壮2014年4月28 日 加油

    第一阶段 第一讲,WEB基础     1.1 网站基本知识: 1.2 网络协议介绍: 1.3 B/S与C/S结构的区别: 1.4 WEB编程.网站开发技术介绍.      第二讲,网页设计     2 ...

  2. Python一路走来 - python基础 数据类型

    对于Python,一切事物都是对象,对象基于类创建 Python数据类型 python主要的数据类型主要包括以下几种类型: (1) 数字型 (2) 字符串 (3) 列表 (4) 元组 (5) 字典 ( ...

  3. 利用Python读取json数据并求数据平均值

    要做的事情:一共十二个月的json数据(即12个json文件),json数据的一个单元如下所示.读取这些数据,并求取各个(100多个)城市年.季度平均值. { "time_point&quo ...

  4. The initialize list of C++ Class

    性能问题之外,有些时场合初始化列表是不可或缺的,以下几种情况时必须使用初始化列表 常量成员,因为常量只能初始化不能赋值,所以必须放在初始化列表里面 Error1(constchar* constmsg ...

  5. static变量的使用

    静态变量 类型说明符是static. 静态变量属于静态存储方式,其存储空间为内存中的静态数据区(在静态存储区内分配存储单元),该区域中的数据在整个程序的运行期间一直占用这些存储空间(在程序整个运行期间 ...

  6. 使用国内镜像更新sdk方法

    使用国内的镜像资源: 1.mirrors.neusoft.edu.cn //东软信息学院 2.ubuntu.buct.edu.cn/ubuntu.buct.cn //北京化工大学 3.mirrors. ...

  7. 将Android 工程从Windows导入到Ubuntu 下java类中的中文在ADT中乱码

    解决方法: 右键工程-->Properties->Resource->Text file encoding->Other 手动输入GBK ->点击OK (Other 中是 ...

  8. QT的文本加密方法(寒山居士)

    http://blog.csdn.net/esonpo/article/details/12746315http://blog.csdn.net/esonpo/article/details/1174 ...

  9. c#调用c++开发的dll const char* 返回值接收问题

    原文:c#调用c++开发的dll const char* 返回值接收问题 用c#调用视频接口相关的dll,dll使用c++开发. c++接口定义如下: PLATFORM const char* Pla ...

  10. libvirtVirsh

    virsh基于不同协议远程连接libvirt drivers(Hypervisors) 基于OS系统账号ssh登陆