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 }

 

转载于:https://www.cnblogs.com/Kiven5197/p/5705368.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值