#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
using namespace std;
int ws(int num)
{
int n = 0;
while (num > 0)
{
num /= 10;
n++;
}
return n;
}
int main()
{
char str[1010],str1[1010];
char word;
char w1=NULL, w2=NULL;
int cou=0;
word=getchar();
getchar();
scanf("%[^\n]", str);
if (word == 'C')
{
for (int i = 0; i <= strlen(str); i++)
{
w2 = str[i];
if (w1 == w2)
cou++;
else
{
if (cou > 0)
cout << cou + 1 << w1;
else if(w1!=NULL)
cout << w1;
cou = 0;
}
w1 = w2;
}
}
else
{
for (int i = 0; i < strlen(str); i++)
{
if (str[i] >= '0'&& str[i] <= '9')
{
strcpy(str1,str + i);
sscanf(str1,"%d",&cou);
i+=ws(cou);
for (int j = 0; j < cou; j++)
cout << str[i];
}
else
cout << str[i];
}
}
system("pause");
return 0;
}
1078 字符串压缩与解压 (20 分)
最新推荐文章于 2020-07-04 22:36:19 发布