题意解释了行程长度编码(Run-Length Encoding),并要求对给定的字符串进行对应的解码。这个题目C语言感觉是非常便捷,用python不知道怎么走捷径,于是只好用土办法一个字符一个字符的判断累加了。。。
python版本AC代码
testcase = int(input())
for i in range(testcase+1):
if i == 0:
continue
strlist = input()
strlen = len(strlist)
j = 0
decodestr = "Case {}: ".format(i)
while j < strlen:
ch = strlist[j]
if ch == '\n':
break
else:
cnt = 0
k = j + 1
while(k < strlen and strlist[k].isdigit()):
cnt *= 10
cnt += int(strlist[k])
k += 1
decodestr += ch * cnt
j = k
print(decodestr)
C/C++版本AC代码
#include <iostream>
#include<cstdio>
using namespace std;
//#define ZANGFONG
int main()
{
#ifdef ZANGFONG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ZANGFONG
int testcase,i,cnt;
char ch;
scanf("%d\n",&testcase);
for(i = 1; i <= testcase; i++)
{
printf("Case %d: ",i);
while(scanf("%c",&ch)!=EOF && ch != '\n')
{
scanf("%d",&cnt);
while(cnt)
{
printf("%c",ch);
cnt--;
}
}
printf("\n");
}
return 0;
}