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"}.
题意:输入n和一个字符串,把字符串分割成n部分,每部分都以不同字母开头
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;
#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define LL long long
#define N 205
#define MOD 19999997
#define INF 0x3f3f3f3f
#define EXP 1e-8
const double Pi = acos(-1.0);
char str[1005];
int n,hsh[30],cnt,len;
int main()
{
scanf("%d%s",&n,str);
len = strlen(str);
int i;
MEM(hsh,0);
UP(i,0,len-1)
{
if(!hsh[str[i]-'a'])
{
hsh[str[i]-'a'] = 1;
cnt++;
}
}
MEM(hsh,0);
if(cnt>=n)
{
printf("YES");
cnt = 0;
UP(i,0,len-1)
{
if(!hsh[str[i]-'a']&&cnt<n)
{
printf("\n");
hsh[str[i]-'a'] = 1;
cnt++;
}
printf("%c",str[i]);
}
printf("\n");
}
else
printf("NO\n");
return 0;
}