|
Description
ZX是另一头04级的牛,他现在在UPen。他跟LLK经常通信,但他不喜欢直接把信息发给LLK,而是把信息通过一个规则转换后再发给LLK,这让LLK很郁闷。他的规则如下:如果字符x出现的n次,则将这几个连在一起的字符表示为xn,例如aaa->a3。为了能读取ZX的信息,亲爱的师弟师妹们,你们可以帮LLK解码吗?
Input
一个字符串S,表示ZX发给LLK的信息,其中字符都是小写字母,数字表示字符出现次数N(1<=N<=10^4);测试数据有多组,S为XXX时,表示结束。
Output
一个字符串T,表示解码后的信息
Sample Input
a3 go12gle XXX
Sample Output
aaa goooooooooooogle | |
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
using namespace std;
int main()
{
string str;
while(cin>>str&&str!="XXX")
{
char ctemp;
for(int i=0;i<str.length();i++)
{
if(isalpha(str[i]))
{
ctemp=str[i];
cout<<str[i];
}
else if(isdigit(str[i]))
{
int temp=0;
while(isdigit(str[i]))
{
temp=temp*10+(str[i]-'0');
i++;
}
for(int j=0;j<temp-1;j++)
cout<<ctemp;
i--;
}
}
cout<<endl;
}
return 0;
}