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
Input1
abcaOutputYES
abcaInput2
aaacasOutputYES
aaa
casInput4
abcOutputNOHint
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
题意:
给你k和一个字符串q,求能否将q分为k份且每一份的首字符各不相同。
可用map来筛选不同的字母的个数,可分为k段则至少有k个不同的字母。输出时再用map记录以用过的首字母。
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std; int main(){
string s,a;
int k,lens,lenm;
cin>>k>>s;
int t=,temp=,ans=;
map<char,int> m;
lens=s.size();
for(int i=;i<lens;i++){
m[s[i]]=;
}
lenm=m.size();
a[]=s[];
if(lens>=k&&lenm>=k){
m.clear();
cout<<"YES"<<endl;
for(int i=;i<lens;i++){
if(m[s[i]]== && temp<k){
if(temp) cout<<endl;
temp++;
}
m[s[i]]++;
cout<<s[i];
}
}
else{
cout<<"NO"<<endl;
}
return ;
}
最新文章
- 【推荐】CentOS安装PHP-5.6.4+扩展安装+安全配置+性能配置
- [z]Java开发必会的Linux命令
- 说说设计模式~门面模式(Facade)
- Lua使用心得(2)
- go println与printf区别
- 63.Hbase 常用命令
- Android之图片窗口和大小调节
- /system改成可写
- iphone屏幕镜像怎么用 手机投屏电脑
- SPOJ GSS系列
- Java POI 读取word文件
- (3.1)mysql基础深入——mysql二进制与源码目录结构介绍
- Linux系统——PXE高效能批量网络装机
- tomcat启动时端口占用的问题怎么解决
- Configure Pi as simulation hardware for Simulink
- 理解webpack4.splitChunks
- Spring Cloud Netflix之Eureka 相关概念
- BestCoder Round #86 二,三题题解(尺取法)
- cocos2d-js中怎么删除一个精灵
- Linux介绍和基本命令
热门文章
- xml文件的根节点layout_width或者layout_height设置无效果的原因分析
- 2016年第七届蓝桥杯c/c++省赛B组
- 内核顶层Makefile相关4
- 实习日记)select option 选择不同的option时, 页面发生不同的变化
- JSP 随记
- vim tips 集锦
- JSP之Model1
- 实例具体解释:反编译Android APK,改动字节码后再回编译成APK
- Spark SQL includes a cost-based optimizer, columnar storage and code generation to make queries fast.
- finding friends with mapreduce