码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces544A:Set of Strings

时间:2015-05-15 15:42:11      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:codeforces

You are given a string q. A sequence of k strings s1,?s2,?...,?sk is called beautiful, if the concatenation of these strings is string q (formally,s1?+?s2?+?...?+?sk?=?q) and the first characters of these strings are distinct.

Find any beautiful sequence of strings or determine that the beautiful sequence doesn‘t exist.

Input

The first line contains a positive integer k (1?≤?k?≤?26) — the number of strings that should be in a beautiful sequence.

The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive.

Output

If such sequence doesn‘t exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next k lines print the beautiful sequence of strings s1,?s2,?...,?sk.

If there are multiple possible answers, print any of them.

Sample test(s)
input
1
abca
output
YES
abca
input
2
aaacas
output
YES
aaa
cas
input
4
abc
output
NO
Note

In the second sample there are two possible answers: {"aaaca",?"s"} and {"aaa",?"cas"}.

题意:输入n和一个字符串,把字符串分割成n部分,每部分都以不同字母开头


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define LL long long
#define N 205
#define MOD 19999997
#define INF 0x3f3f3f3f
#define EXP 1e-8

const double Pi = acos(-1.0);
char str[1005];
int n,hsh[30],cnt,len;

int main()
{
    scanf("%d%s",&n,str);
    len = strlen(str);
    int i;
    MEM(hsh,0);
    UP(i,0,len-1)
    {
        if(!hsh[str[i]-'a'])
        {
            hsh[str[i]-'a'] = 1;
            cnt++;
        }
    }
    MEM(hsh,0);
    if(cnt>=n)
    {
        printf("YES");
        cnt = 0;
        UP(i,0,len-1)
        {
            if(!hsh[str[i]-'a']&&cnt<n)
            {
                printf("\n");
                hsh[str[i]-'a'] = 1;
                cnt++;
            }
            printf("%c",str[i]);
        }
        printf("\n");
    }
    else
        printf("NO\n");

    return 0;
}


Codeforces544A:Set of Strings

标签:codeforces

原文地址:http://blog.csdn.net/libin56842/article/details/45743599

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!