A - Set of Strings

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

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 Input

Input
1
abca
Output
YES
abca
Input
2
aaacas
Output
YES
aaa
cas
Input
4
abc
Output
NO

Hint

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

 

题意:

给你k和一个字符串q,求能否将q分为k份且每一份的首字符各不相同。

 

可用map来筛选不同的字母的个数,可分为k段则至少有k个不同的字母。输出时再用map记录以用过的首字母。

 

附AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<map>
 6 #include<algorithm>
 7 using namespace std;
 8 
 9 int main(){
10     string s,a;
11     int k,lens,lenm;
12     cin>>k>>s;
13     int t=1,temp=0,ans=0;
14     map<char,int> m;
15     lens=s.size();
16     for(int i=0;i<lens;i++){
17         m[s[i]]=1;
18     }
19     lenm=m.size();
20     a[0]=s[0];
21     if(lens>=k&&lenm>=k){
22         m.clear();
23         cout<<"YES"<<endl;
24             for(int i=0;i<lens;i++){
25                 if(m[s[i]]==0 && temp<k){
26                 if(temp) cout<<endl;
27                 temp++;
28             }
29             m[s[i]]++;
30             cout<<s[i];
31             }
32     }
33     else{
34         cout<<"NO"<<endl;
35     }
36     return 0;
37 }

 

posted @ 2016-07-25 21:13  Kiven#5197  阅读(162)  评论(0编辑  收藏  举报