Codeforces 44E - Anfisa the Monkey - [水题]

题目链接:http://codeforces.com/problemset/problem/44/E

题意:

给一个字符串,让你分割成 $k$ 行,每行的字母数在 $[a,b]$ 之间。

题解:

这是1500difficulty的DP题?

AC代码:

#include<bits/stdc++.h>
using namespace std;
int k,a,b;
string s;
int main()
{
    cin>>k>>a>>b;
    cin>>s;

    if(s.size()<k*a || k*b<s.size()) cout<<"No solution"<<endl;
    else
    {
        int c=s.size()/k, p=0;
        for(int r=1;r<=k;r++)
        {
            if(r<k)
            {
                for(int i=1;i<=c;i++) cout<<s[p++];
                cout<<endl;
            }
            else
            {
                while(p<s.size()) cout<<s[p++];
                cout<<endl;
            }
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/dilthey/p/10460141.html