Anfisa the Monkey

Anfisa the Monkey

Time limit 2000 ms
Memory limit 262144 kB

Anfisa the monkey learns to type. She is yet unfamiliar with the “space” key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into k lines not shorter than a and not longer than b, for the text to resemble human speech more. Help Anfisa.

Input

The first line contains three integers k, a and b (1 ≤ k ≤ 200, 1 ≤ a ≤ b ≤ 200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols.

Output

Print k lines, each of which contains no less than a and no more than b symbols — Anfisa’s text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print “No solution” (without quotes).

Examples

Input
3 2 5
abrakadabra
Output
ab
rakad
abra
Input
4 1 2
abrakadabra
Output
No solution

#include<stdio.h>
#include<string.h>
int main()
{
    int k,a,b,d[200],i,j,x;
    char p[201];
    while(~scanf("%d %d %d",&k,&a,&b))
    {
        getchar();
        gets(p);
        x=strlen(p);
        if(k>200||x==0) break;
        if(x>b*k||x<a*k) printf("No solution\n");
        else
        {
            for(i=0;i<k;i++)
            {
                d[i]=a;
            }
            x-=(a*k);
            while(x)
            {
                for(i=0;i<k;i++)
                {
                    d[i]++;
                    x--;
                    if(x==0)
                    {
                        break;
                    }
                }
            }
            j=0;
            for(i=0;i<k;i++)
            {
                while(d[i]--)
                {
                    printf("%c",p[j]);
                    j++;
                }
                printf("\n");
            }
        }
    }
    return 0;
}

My Ideas

Make a judgment on whether it exists.
If so, then each group has at least ‘a’ characters, so give each group a initial value ‘a’.
Next, add the rest to the array through a loop.

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值