A. The Text Splitting

题目连接:

http://www.codeforces.com/contest/612/problem/A

Description

You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.

For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".

Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).

Input

The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100).

The second line contains the string s consists of lowercase and uppercase latin letters and digits.

Output

If it's impossible to split the string s to the strings of length p and q print the only number "-1".

Otherwise in the first line print integer k — the number of strings in partition of s.

Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right.

If there are several solutions print any of them.

Sample Input

5 2 3

Hello

Sample Output

2

He

llo

Hint

题意

给你一个字符串,让你分割成长度为p,或者长度为q的串

问你如何分割

题解:

数据范围很小,所以直接暴力枚举就好了

代码

#include<bits/stdc++.h>
using namespace std; string s;
int main()
{
int n,p,q;
cin>>n>>p>>q;
cin>>s;
for(int i=0;i<150;i++)
{
for(int j=0;j<150;j++)
{
if(i*p+j*q==s.size())
{
cout<<i+j<<endl;
for(int k=0;k<i;k++)
{
for(int t=0;t<p;t++)
cout<<s[k*p+t];
cout<<endl;
}
for(int k=0;k<j;k++)
{
for(int t=0;t<q;t++)
cout<<s[i*p+k*q+t];
cout<<endl;
}
return 0;
}
}
}
return puts("-1");
}

Educational Codeforces Round 4 A. The Text Splitting 水题的更多相关文章

  1. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  2. Codeforces Educational Codeforces Round 3 B. The Best Gift 水题

    B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...

  3. Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题

    A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...

  4. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  5. Educational Codeforces Round 13 C. Joty and Chocolate 水题

    C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...

  6. Educational Codeforces Round 13 B. The Same Calendar 水题

    B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...

  7. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

  8. Educational Codeforces Round 12 A. Buses Between Cities 水题

    A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...

  9. Educational Codeforces Round 11 B. Seating On Bus 水题

    B. Seating On Bus 题目连接: http://www.codeforces.com/contest/660/problem/B Description Consider 2n rows ...

随机推荐

  1. 修改 AndroidManifest minSdkVersion 的方法

    1.修改AndroidManifest文件    使用16进制编辑器检索位置:FF FF FF FF 08 00 00 10 ??    将??替换为原APK的minSdkVersion对应的16进制 ...

  2. D.xml

    pre{ line-height:1; color:#1e1e1e; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#627cf6; ...

  3. 通过ajax提交form表单

    $.ajax({ url : 'deliveryWarrant/update.do', data : $('#myform').serialize(), type : "POST" ...

  4. Zookeeper,Hbase 伪分布,集群搭建

    工作中一般使用的都是zookeeper和Hbase的分布式集群. more /etc/profile cd /usr/local zookeeper-3.4.5.tar.gz zookeeper在安装 ...

  5. [ZZ] C++ pair

    Pair类型概述 pair是一种模板类型,其中包含两个数据值,两个数据的类型可以不同,基本的定义如下: pair<int, string> a; 表示a中有两个类型,第一个元素是int型的 ...

  6. Sql group by 分组取时间最新的一条数据

    with MiPriceTopOne as (select classid,max(dataTime) dataTime,max(id) as id from MiPrice group by cla ...

  7. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...

  8. 第三百五十二天 how can I 坚持

    如果要是今年找不到对象,明年去回济南, 怎么感觉那么不舍呢.生活总是有太多的无奈啊. 今天加了一天,倒是没感觉,只是感觉生活太空虚. 或许遗憾只是因为自己太懦弱.怎么说呢,还是那句话,经历的就会成长, ...

  9. 【转】MySQL索引和查询优化

    原文链接:http://www.cnblogs.com/mailingfeng/archive/2012/09/26/2704344.html 对于任何DBMS,索引都是进行优化的最主要的因素.对于少 ...

  10. HD2029

    Palindromes _easy version Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...