武汉科技大学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 ...
随机推荐
- PHP微信红包的算法实现探讨
header("Content-Type: text/html;charset=utf-8");//输出不乱码,你懂的 $total=10;//红包总额 $num=8;// 分成8 ...
- 转载自php100中文网 centos下lamp 环境搭建
学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.MySQL.PHP环境. 一. ...
- C程序设计语言练习题1-14
练习1-14 编写一个程序,打印输入中各个字符出现频度的直方图. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() // 定义名为main的 ...
- Android Canvas.drawText方法中的坐标参数的正确解释
摘要 canvas.drawText(www.jcodecraeer.com, x, y, paint); x和y参数是指定字符串中心的坐标吗?还是左上角的坐标?这个问题的直观印象应该是左上角的坐标, ...
- BZOJ3401: [Usaco2009 Mar]Look Up 仰望
3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 87 Solved: 58[Submit ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- Cookie和Session(转)
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...
- redis 网络流程图 <一>
本来一直想好好读下redis源码.可是每次读了一点就不读了. 主要是没坚持每天都读. 隔几天看.就忘记前面的流程.就越来越不想看了. 很是蛋疼.这个还是要坚持读完的.打算这段时间都源码的时候.都大 ...
- java的动态代理设计模式
代码实现: package com.lky.proxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Me ...
- 【KMP】Cyclic Nacklace
KMP算法 next[]深入了解,做到这题才真正明白next[]的用法,希望后面的题目能理解的更深刻. Problem Description CC always becomes very depre ...