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 1 to 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
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
做简单题目,慢慢来,想快点,写好点
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <cstring> 2 #include <cstdio> 3 #include <iostream> 4 #include <set> 5 using namespace std; 6 7 int main() 8 { 9 //freopen("in.txt", "r", stdin); 10 int nstr; 11 12 while(scanf("%d", &nstr) != EOF) 13 { 14 getchar(); 15 char str[105]; 16 bool vis[105]; 17 gets(str); 18 int len = strlen(str); 19 memset(vis, false, sizeof(vis)); 20 21 set<char> s; 22 23 int p = 0; 24 s.insert(str[0]); 25 ++p; 26 vis[0] = true; 27 if(p != nstr) 28 { 29 for(int i = 1; i != len; ++i) 30 { 31 if(s.find(str[i]) == s.end() && p < nstr) 32 { 33 s.insert(str[i]); 34 ++p; 35 vis[i] = true; 36 } 37 } 38 } 39 40 if(p < nstr) 41 { 42 cout << "NO" << endl; 43 } 44 else 45 { 46 cout << "YES" << endl; 47 for(int i = 0; i != len; ++i) 48 { 49 if(vis[i] == true) 50 { 51 putchar(str[i]); 52 int j = i+1; 53 while(vis[j] == false && j < len) 54 { 55 putchar(str[j]); 56 ++j; 57 } 58 puts(""); 59 } 60 } 61 } 62 } 63 return 0; 64 }