Codeforces544A:Set of Strings

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值