| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 191387 人关注过本帖, 1 人收藏
标题:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
只看楼主 加入收藏
不在状态
Rank: 1
来 自:河北
等 级:新手上路
帖 子:23
专家分:0
注 册:2011-10-19
结帖率:75%
收藏(1)
已结贴  问题点数:0 回复次数:30 
输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
帮忙写上代码分析。
搜索更多相关主题的帖子: 统计 分析 英文字母 
2011-10-24 19:13
smallmoon521
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:517
专家分:1373
注 册:2008-4-21
收藏
得分:1 
从ASCII码入手,这就是思路

为游戏狂~~!!    大家努力编哈!
2011-10-24 19:39
laznrbfe
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:482
专家分:1599
注 册:2011-5-22
收藏
得分:1 
程序代码:
#include<stdio.h>
int main(void)
{
    //输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
    char ch;
    int char_num=0,kongge_num=0,int_num=0,other_num=0;
    while((ch=getchar())!='\n')//回车键结束输入,并且回车符不计入
    {
        if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a')
        {
            char_num++;
        }
        else if(ch==' ')
        {
            kongge_num++;
        }
        else if(ch>='0'&&ch<='9')
        {
            int_num++;
        }
        else
        {
            other_num++;
        }
    }
    printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);
    return 0;
}
2011-10-24 20:07
Y_Jo_1
Rank: 4
等 级:业余侠客
帖 子:59
专家分:215
注 册:2011-10-20
收藏
得分:1 
楼上的这个很好啊

#include<stdio.h>
main()
{
    char ch;
    int char_num=0,kongge_num=0,int_num=0,other_num=0;
    while((ch=getchar())!='\n')    {
        if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a')
        {
            char_num++;
        }
        else if(ch==' ')
        {
            kongge_num++;
        }
        else if(ch>='0'&&ch<='9')
        {
            int_num++;
        }
        else
        {
            other_num++;
        }
    }
    printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);
    return 0;
}
2011-10-24 22:00
lingandyi
Rank: 1
等 级:新手上路
帖 子:97
专家分:3
注 册:2007-2-25
收藏
得分:1 
同意三楼的

2011-10-24 22:11
lowkey_c
Rank: 2
等 级:论坛游民
帖 子:19
专家分:28
注 册:2011-10-14
收藏
得分:1 
以下是引用Y_Jo_1在2011-10-24 22:00:00的发言:

楼上的这个很好啊

#include
main()
{
    char ch;
    int char_num=0,kongge_num=0,int_num=0,other_num=0;
    while((ch=getchar())!='\n')    {
        if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a')
        {
            char_num++;
        }
        else if(ch==' ')
        {
            kongge_num++;
        }
        else if(ch>='0'&&ch<='9')
        {
            int_num++;
        }
        else
        {
            other_num++;
        }
    }
    printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num);
    return 0;
}
LS+1
2011-10-24 22:22
weiwei555
Rank: 5Rank: 5
来 自:中国
等 级:职业侠客
帖 子:179
专家分:323
注 册:2011-3-4
收藏
得分:1 
二级的?
2011-10-24 22:24
吴军旗
Rank: 5Rank: 5
等 级:职业侠客
帖 子:286
专家分:308
注 册:2011-9-14
收藏
得分:1 
别急着结,我想想。。。。。。。。用别的方法。。。

最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
2011-10-24 22:31
吴军旗
Rank: 5Rank: 5
等 级:职业侠客
帖 子:286
专家分:308
注 册:2011-9-14
收藏
得分:0 
程序代码:
#include < stdio.h >
#include < stdlib.h >
#include < ctype.h >

void main ( )
{
    char ch;
    int sum1 = 0;
    int sum2 = 0;
    int sum3 = 0;
    int sum4 = 0;
    while((ch=getchar())!='\n')
    {
        if ( isdigit ( ch ) != 0 )
            sum1++;
        else if ( isspace ( ch ) != 0 )
            sum2++;
        else if ( islower ( ch ) != 0 || isupper ( ch ) != 0 )
            sum3++;
        else
            sum4++;
    }
    printf ( "%5d%5d%5d%5d", sum1, sum2, sum3, sum4 );
    system ( "pause" );
}
果然我用函数做出来了,呵呵,为自己高兴。。。。。。。。。。。。

最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
2011-10-24 22:47
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:1 
回复 9楼 吴军旗
鼓励一下

授人以渔,不授人以鱼。
2011-10-24 23:20
快速回复:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016077 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved