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 ...
随机推荐
- Java EJB JBoss
JBoss:JBoss是web服务器的一种,主要做EJB容器,和tomcat集成就可以jsp,servlet,ejb通吃了JBoss有两种版本,一种是独立的,一种是和tomcat集成的,当然都是免费的 ...
- linux find prune排除某目录或文件
http://blog.csdn.net/ysdaniel/article/details/7995681 查找cache目录下不是html的文件 find ./cache ! -name '*.ht ...
- response响应和User-Agent历史
返回百度的源码,没有任何伪装: response是服务器响应的类文件,除了支持文件操作的方法以外,还支持以下方法:
- vim调试
首先,想调试一个程序的话,输入以下命令: guest-djjtew@ubuntu:~$ python3 -m pdb 1.py 这时候就停止了,等待着你的输入,然后输入"l"的话, ...
- Ubuntu16.04上安装mongoDB
安装MongoDB 现在最新版本是3.4 1: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F37303 ...
- HDU 1418 抱歉 (欧拉公式)
[题目链接]:pid=1418">click here~~ [题目大意]: 假设平面上有n个点,而且每一个点至少有2条曲线段和它相连,就是说,每条曲线都是封闭的.同一时候,我们规定: ...
- Mapreduce实战:序列化与反序列化 int,int[],string[][]
最新一期<中国IT产业发展报告>在2016中国(深圳)IT领袖峰会上正式发布,数字中国联合会常务理事李颖称.中国IT产业完毕了从要素驱动向效率驱动的过渡,眼下正在由效率驱动向创新驱动发展. ...
- Struts2 实例(转载)
一.准备工作及实例 1.解压struts-2.1.6-all.zip apps目录:struts2自带的例子程序docs目录:官方文档. lib 目录:存放所有jar文件. Src 目录:源文件存放地 ...
- linux 中添加自己的库路径的方法 cannot open shared object file: No such file or directory
本文转自:http://blog.csdn.net/maotianwang/article/details/44619197 库文档在连接(静态库和共享库)和运行(仅限于使用共享库的程式)时被使用,其 ...
- python网络爬虫之使用scrapy下载文件
前面介绍了ImagesPipeline用于下载图片,Scrapy还提供了FilesPipeline用与文件下载.和之前的ImagesPipeline一样,FilesPipeline使用时只需要通过it ...