<分区>
我有一个类似于下面的 aa4bccc3d 的字符串,我需要将它转换为 aabbbbcccddd 我的解决方案有效,但我不知道如何恢复这样的情况: a25b 应解码为 abbbbbbbbbbbbbbbbbbbbbbbbb 或 125b 大小写。
string convert(string c) {
string result = "";
for (int i = 0; i < c.size(); i++) {
if (c[i] >= 'a' && c[i] <= 'z') {
result += c[i];
} else if (c[i]-'0' >= 0 && c[i]-'0' <= 9) {
if (i < c.size()) {
int prevI = i;
int nextJ = i;
if (c[++nextJ] >= 'a' && c[++nextJ] <= 'z') {
for (int j = 0; j < c[prevI]-'0'; j++ {
result += c[prevI+1];
}
}
}
}
}
return result;
}