Chinaunix首页 | 论坛 | 博客
  • 博客访问: 209860
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: C/C++

2011-03-14 10:56:27

 #include    "stdio.h"

/* count digits, white space, others */
main()
{
    int c, i, nwhite, nother;
    int ndigit[10];

    nwhite = nother = 0;
    for (i = 0; i < 10; ++i)
      ndigit[i] = 0;

    while ((c = getchar()) != EOF)
      if (c >= '0' && c <= '9')
        ++ndigit[c-'0'];
      else if (c == ' ' || c == '\n' || c == '\t')
        ++nwhite;
      else
        ++nother;

    printf ("digits = ");
    for (i = 0; i < 10; ++i)
          printf (" %d", ndigit[i]);
    printf (", white sapce = %d, other = %d\n", nwhite, nother);
}

阅读(320) | 评论(0) | 转发(0) |
0

上一篇:K&R(1): Functions

下一篇:tpop(2.1): Searching

给主人留下些什么吧!~~