码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 544A

时间:2015-05-18 22:56:44      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

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 test(s)
Input
1
abca
Output
YES
abca
Input
2
aaacas
Output
YES
aaa
cas
Input
4
abc
Output
NO
Note

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

做简单题目,慢慢来,想快点,写好点

 

技术分享
 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 }
View Code

 

CodeForces 544A

标签:

原文地址:http://www.cnblogs.com/ya-cpp/p/4513196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!