Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2552158
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: C/C++

2012-11-06 20:23:10

点击(此处)折叠或打开

  1. #include <stdio.h>
  2.  #include <string.h>
  3.  
  4.  #define LEN 128
  5.  
  6.  static int out[LEN] = {0};
  7.  
  8.  /**
  9.   * 利用ascii映射求得字符串中字符的个数
  10.   * 思路来自:http://blog.csdn.net/gukesdo/article/details/7072132
  11.   */
  12.  void calculate(const char * str)
  13.  {
  14.      const char * p = str;
  15.      if (!p)
  16.          return ;
  17.      while (*p) //切忌while(p),p!=NULL;而是内容为\0
  18.      {
  19.          out[*p] += 1;
  20.          p++;
  21.      }
  22.  }
  23.  
  24.  //check
  25.  void showRs(int a[], int len)
  26.  {
  27.      int i = 0;
  28.      for ( ; i < len; ++i)
  29.      {
  30.          //printf("%d -> %d & ", i, a[i]);
  31.          //改进下
  32.          printf("%c -> %d & ", i, a[i]);
  33.          if (!((i + 1)%4))
  34.              putchar('\n');
  35.      }
  36.  }
  37.  
  38.  /**
  39.   * 有时候就怕你不敢想,而不是做不到!
  40.   */
  41.  int main(int argc, const char *argv[])
  42.  {
  43.      calculate("we are friends!");
  44.      showRs(out, LEN);
  45.      return 0;
  46.  }

阅读(2411) | 评论(0) | 转发(1) |
0

上一篇:链表逆序-me

下一篇:Genius Singer

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