武汉科技大学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 ...
随机推荐
- jquery读取后台代码
前台代码: <script type="text/javascript"> $(function () { $("#btn") ...
- NSSet和NSMutableSet 确保数据的唯一性--备
NSSet和NSMutableSet是无序的, 但是它保证数据的唯一性.当插入相同的数据时,不会有任何效果.从内部实现来说是hash表,所以可以常数时间内查找一个数据. 1.NSSet的使用 [NSS ...
- JS Map 简单实现
/* * MAP对象,实现MAP功能 * * 接口: * size() 获取MAP元素个数 * isEmpty() 判断MAP是否为空 * clear() 删除MAP所有元素 * put(key, v ...
- 用Setup系列函数完成驱动卸载安装[驱动安装卸载程序]
// InstallWDFDriver.cpp : Defines the entry point for the console application. // #include "std ...
- HDOJ 1390 Binary Numbers(进制问题)
Problem Description Given a positive integer n, find the positions of all 1's in its binary represen ...
- java的CalssLoader
类加载器是 Java 语言的一个创新,也是 Java 语言流行的重要原因之一.它使得 Java 类可以被动态加载到 Java 虚拟机中并执行.类加载器从 JDK 1.0 就出现了,最初是为了满足 Ja ...
- jsp中pageEncoding、charset=UTF -8
jsp中pageEncoding.charset=UTF -8" 在JSP/Servlet 中主要有以下几个地方可以设置编码,pageEncoding="UTF-8". ...
- (2015多校第6场)HDU5361--In Touch (Dijkstra应用)
In Touch Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- java中文乱码解决之道(六)—–javaWeb中的编码解码
在上篇博客中LZ介绍了前面两种场景(IO.内存)中的java编码解码操作,其实在这两种场景中我们只需要在编码解码过程中设置正确的编码解码方式一般而言是不会出现乱码的.对于我们从事java开发的人而言, ...
- 司机福利!Uber即将可以自己选目的地接单啦!
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...