问题描述:
Choice喜欢把连续相同的字符转换成字符和数字,而且她表达的数字都是一位的,比如”c22”就是”ccccc”,即每位数字表示重复上一个最近出现的字符次数。你能将Choice写的字符串还原吗?
输入:
第一行输入一个整数T,表示测试组数。
每组数据包括一行,输入一个Choice写的字符串,长度小于100(第一位不会出现数字)
输出:
每组输出一行,表示展开后的字符串。
样例输入:
1 a3b4c22
样例输出:
aaaabbbbbccccc
原因分析:
多实例 注意是否需要换行(一般都需要),不换行肯定就错了.
解决方案:
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
char c;
string str;
int num,i,j,k;
cin>>str;
k=str.length();
for(i=0;i<k;i++)
{
if(str[i]>='0'&&str[i]<='9')
{
num=str[i]-'0';
for(j=1;j<=num;j++)
cout<<c;
}
else
{
c=str[i];
cout<<c;
}
}
cout<<endl;
}
return 0;
}