1 /* 2 题意:一个字符串分割成k段,每段开头字母不相同 3 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <string> 9 #include <algorithm> 10 using namespace std; 11 12 const int MAXN = 1e2 + 10; 13 const int INF = 0x3f3f3f3f; 14 char s[MAXN]; 15 int num[30]; 16 17 int main(void) //Codeforces Round #302 (Div. 2) A Set of Strings 18 { 19 //freopen ("A.in", "r", stdin); 20 21 int k; 22 while (scanf ("%d", &k) == 1) 23 { 24 scanf ("%s", &s); 25 if (k == 1) {puts ("YES"); printf ("%s\n", s); continue;} 26 27 memset (num, 0, sizeof (num)); 28 int len = strlen (s); 29 for (int i=0; i<len; ++i) num[s[i]-'a']++; 30 int t = 0; 31 for (int i=0; i<26; ++i) if (num[i]) ++t; 32 if (t < k) {puts ("NO"); continue;} 33 34 puts ("YES"); 35 printf ("%c", s[0]); num[s[0]-'a'] = 0; 36 int p = 0; int i; 37 for (i=1; i<len; ++i) 38 { 39 if (!num[s[i]-'a']) {printf ("%c", s[i]);} 40 else 41 { 42 num[s[i]-'a'] = 0; puts (""); 43 printf ("%c", s[i]); ++p; 44 } 45 if (p == k - 1) break; 46 } 47 48 for (int j=i+1; j<len; ++j) printf ("%c", s[j]); 49 puts (""); 50 } 51 52 return 0; 53 }