简单字符串(1)

今天在新网站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;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值