> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/letcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/letcode/2-count-and-say-1/c-solution.md).

# c-solution

## 1.solution

```
 char* countAndSay(int n) {
  char * ary = (char *)malloc(5000 * sizeof(char));
  char * oldAry = (char *)malloc(5000 * sizeof(char));
  n = n -1;
  oldAry[0] = '1';
  ary[0] = '1';
  int round = 0;
  int count = 1;
  int index = 0;
  int len = 1;

  while(round < n){
      round = round +1;
      index = 0;
      for(int i = 0 ; i < len; i++){
          if (oldAry[i] == oldAry[i + 1] )
          {
              //計算重複的數量
              count = count + 1;        
          }else{
              //數量 -> 將數字(1~9)轉到字元
              ary[index++] = count+'0';
              //什麼數字
              ary[index++] = oldAry[i];
              count = 1;    
          }
      }
      //上一次的字元數量
      len = index ;
      //結束字元
      ary[index++] = '\0';
      memcpy(oldAry, ary, len);

  }
  free(oldAry);
  return ary;
 }
```

## 2.performance

![](https://github.com/jenhsuan/letcode/tree/4999a189073590294b35b42c8dfe17f9b5bebfad/assets/螢幕快照%202017-05-04%20下午5.37.56.png)
