今天在新网站Codingame刷题,刚开始做的题目不是很难,但对练习手速很有帮助.
题型有3种:
Fastest(最快做出)
You must complete the puzzle as fast as possible.
Shortest(写出最短的代码)
You need to write the lowest code size. Take your time hack your way to the shortest solution!
Reverse(根据输入输出写中间代码)
You have to guess what to do by observing the provided set of tests.
如果难题不会,会做的题手速快在ACM比赛中也是一种优势…
现在进入正题:
描述
输入一个字符串,输出结果。具体见Input,Output
Input:
1a2b3c
Output:
a
bb
ccc
Input:
3ll4fff5sox
Output:
ll
ll
ll
fff
fff
fff
fff
sox
sox
sox
sox
sox
#include<bits/stdc++.h>
using namespace std;
inline int pd1(char ch){
return (ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z') ;
}
inline int pd2(char ch){
return (ch>='0'&&ch<='9');
}
void f(char str[]){
for(int i=0;i<strlen(str);){
int j;
int c=0;
for(j=0;pd2(str[i+j]);j++){
c=c*10+str[i+j]-'0';
}
//printf("c=%d\n",c);
i+=j;
char t[100];
int top=0;
memset(t,0,sizeof(t));
for(j=0;pd1(str[i+j]);){
t[top]=str[i+j];
top++;
j++;
}
i+=j;
for(int k=0;k<c;k++){
printf("%s\n",t);
}
}
}
int main(){
char str[1000];
cin>>str;
f(str);
return 0;
}