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 ;
}
A - Set of Strings的更多相关文章
- Hacker Rank: Two Strings - thinking in C# 15+ ways
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...
- StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing the strings?
StackOverFlow排错翻译 - Python字符串替换: How do I replace everything between two strings without replacing t ...
- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Encode and Decode Strings 加码解码字符串
Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...
- [LeetCode] Group Shifted Strings 群组偏移字符串
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- [LeetCode] Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- [LeetCode] Multiply Strings 字符串相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 使用strings查看二进制文件中的字符串
使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
随机推荐
- PCIE、UART、HDA、I2C、SMBUS、SPI、eSPI、USB、PS2、CAN、SDIO等数据传输协议简介
M.2 wife一般支持USB.SDIO.PCIE三种传输 1.摄像头 (1)MIPI CSI (2)USB mipi摄像头模组IC简单便宜(小),应为一般把ADC解码在CPU端. MIPI摄像头简介 ...
- 后台运行命令:&和nohup command & 以及关闭、查看后台任务
当我们在终端或控制台工作时.可能不希望由于执行一个作业而占住了屏幕,由于可能还有更重要的事情要做,比方阅读电子邮件. 对于密集訪问磁盘的进程,我们更希望它可以在每天的非负荷高峰时间段执行(比如凌晨). ...
- Linux机器间ssh免密登录
前言 一台Linux机器通过ssh的方式连接别的机器或通过scp的方式传输文件,都需要输入密码. 为了解决每次输入密码的困扰,可采用添加密钥的方式实现. 实现过程 源服务器A,目标服务器B. 1.在源 ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- VS重置命令:devenv.exe/resetuserdata
VS命令行下执行下面的命令: devenv.exe/resetuserdata
- 【BZOJ2161】布娃娃 扫描线+线段树
[BZOJ2161]布娃娃 Description 小时候的雨荨非常听话,是父母眼中的好孩子.在学校是老师的左右手,同学的好榜样.后来她成为艾利斯顿第二代考神,这和小时候培养的良好素质是分不开的.雨荨 ...
- 开源流媒体服务器EasyDarwin支持epoll网络模型,大大提升流媒体服务器网络并发性能
经过春节前后将近2个月的开发和稳定调试.测试,EasyDarwin开源流媒体服务器终于成功将底层select网络模型修改优化成epoll网络模型,将EasyDarwin流媒体服务器在网络处理的效率上提 ...
- please add a 'mainClass’ property
when build an spring project with this command: mvn spring-boot:run there will may show an error mes ...
- pexpect库学习之包装类详解
在pexpect库中,包装类的构造参数使用的命令或者要包装命令的提示符,还可以通过这个包装类来修改命令的提示符,那么所谓的包装类实际就是用于给用户交互相应的子命令,它的实例方法主要是“run_comm ...
- 关于myeclipse缓存问题
昨天在部署项目的时候发现,刚检出的项目jdk竟然不是1.6版本的了,而是新的(在此之前每次检出项目都会重新设置一下jdk),如图所示: 当时还在想,真好,以后就不用配置了,但是随之而来的是一个重大问题 ...