junior19

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

A. Set of Strings
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
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"}.


题意:判断能否将字符串分成连续的k份,且各部份首字母没有重复。

思路:给每个位置打个标志再输出即可。

# include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, icount, flag[103], vis[30];
    char s[103];
    while(~scanf("%d%s",&k,s))
    {
        icount = 0;
        memset(flag, 0, sizeof(flag));
        memset(vis, 0, sizeof(vis));
        int len = strlen(s);
        if(k > len)
        {
            puts("NO");
            continue;
        }
        for(int i=0; i<len&&icount<k; ++i)
        {
            int n = s[i]- 'a';
            if(!vis[n])
            {
                vis[n] = 1;
                flag[i] = 1;
                ++icount;
            }
        }
        if(icount != k)
        {
            puts("NO");
            continue;
        }
        puts("YES");
        putchar(s[0]);
        for(int i=1; i<len; ++i)
        {
            if(flag[i] == 1)
                printf("\n");
            putchar(s[i]);
        }
        printf("\n");
    }
    return 0;
}



posted on 2017-03-23 17:25  junior19  阅读(147)  评论(0编辑  收藏  举报