Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56707
  • 博文数量: 29
  • 博客积分: 667
  • 博客等级: 上士
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-11 15:55
文章分类
文章存档

2012年(2)

2011年(27)

我的朋友
最近访客

分类: C/C++

2011-10-13 12:05:18

abbcccdddeeeee  -→1a2b3c4d5e

  1. #include<iostream>
  2. #include<string>

  3. using namespace std;
  4. int main()
  5. {
  6.     char str[51];
  7.     char tmp[51];

  8.     while(gets(str)) {
  9.         int len = strlen(str);
  10.         int index = 0;
  11.         int count = 1;

  12.         for(int i = 0; i < len; i++) {
  13.             if(str[i] == str[i+1])
  14.                 count ++;
  15.             else {
  16.                 tmp[index++] = count + '0';
  17.                 tmp[index++] = str[i];
  18.                 count = 1;
  19.             }
  20.         }
  21.         tmp[index] = '\0';
  22.         strcpy(str,tmp);
  23.         cout << str << endl;
  24.     }
  25.     return 0;
  26. }
阅读(366) | 评论(0) | 转发(0) |
0

上一篇:读程序题-2

下一篇:代码-全排列问题

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