首页 技术 正文
技术 2022年11月17日
0 收藏 325 点赞 2,777 浏览 2364 个字

A. Set of Strings

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/544/problem/A

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

1
abca

Sample Output

YES
abca

HINT

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

题意

把一个字符串能不能拆成N份,要求每一份的开头字母都不相同

题解:

统计一下有多少个不同的字母,如果小于n,那就直接输出no

否则就输出这些分开的字符串就好了~

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/*inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//**************************************************************************************string s;
map<char,int> H;
int flag[maxn];
int main()
{
int n=read();
int ans=;
cin>>s;
for(int i=;i<s.size();i++)
{
if(H[s[i]])
continue;
H[s[i]]=;
flag[ans]=i;
ans++;
}
if(ans<n)
{
puts("NO");
return ;
}
puts("YES");
for(int j=;j<n-;j++)
{
for(int i=flag[j];i<flag[j+];i++)
cout<<s[i];
cout<<endl;
}
for(int i=flag[n-];i<s.size();i++)
cout<<s[i];
cout<<endl;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,115
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,587
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,433
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,204
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,840
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,925