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. IRequiresSessionState和IReadOnlySessionState应用上的一些差异

    在调用ashx时,如果需要应用Session,则必须继承接口 IRequiresSessionState,IReadOnlySessionState,但根据字面,可以知道 IRequiresSessi ...

  2. 【python】python+behave自动化

    留坑,后面再写,先写下request对http请求的校验.

  3. dword word byte 相互转换 .xml

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

  4. Page 63-64 Exercises 2.3.7 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)

    Use the following method printPrimes() for question a-d below //Find and prints n prime integers pri ...

  5. Epic - Snake Sequence

    You are given a grid of numbers. A snakes equence is made up of adjacent numbers such that for each ...

  6. MySQL安装(图文详解)

    下面的是MySQL安装的图解,用的可执行文件安装的,详细说明了一下!打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩,运行“setup.exe”,出现如下界面 my ...

  7. CentOS下安装R

    R的Windows版本有直接的安装包,直接下载安装很方便,但是对于CentOS6以上,不能直接通过yum 安装R,需要自己编译. 1. 在编译之前,用yum安装各种软件 (1)安装gcc > y ...

  8. 在使用EF开发时候,遇到 using 语句中使用的类型必须可隐式转换为“System.IDisposable“ 这个问题。

    原因就是 这个程序集中没有引用EntityFramework.可以使用Nuget 安装EntityFramewok.

  9. mysql基础知识(4)--修改

    修改表: 一般概述 通常,创建一个表,能搞定(做到)的事情,修改表也能做到.大体来说,就可以做到: 增删改字段: 增:alter  table  表名  add  [column]  字段名  字段类 ...

  10. #用Python直接写UTF-8文本文件

    当我们这样建立文件时 f = file('x1.txt', 'w') f.write(u'中文') f.colse() 直接结果应该是类似 f.write(u'中文') UnicodeEncodeEr ...