1 second
256 megabytes
standard input
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.
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 1to 100, inclusive.
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.
1
abca
YES
abca
2
aaacas
YES
aaa
cas
4
abc
NO
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <map>
#include <ctime>
using namespace std; bool VIS[];
int main(void)
{
char q[];
int a,num;
int loc[];
num = ; scanf("%d",&a);
scanf("%s",q);
for(int i = ;q[i];i ++)
if(!VIS[q[i]])
{
VIS[q[i]] = true;
loc[num] = i;
num ++;
}
loc[num] = strlen(q); if(num < a)
puts("NO");
else
{
puts("YES");
for(int i = ;i < a;i ++)
{
if(i == a - )
for(int j = loc[i];q[j];j ++)
printf("%c",q[j]);
else
for(int j = loc[i];j < loc[i + ];j ++)
printf("%c",q[j]);
puts("");
}
} return ;
}