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

Input
1
abca
Output
YES
abca
Input
2
aaacas
Output
YES
aaa
cas
Input
4
abc
Output
NO

Hint

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的更多相关文章

  1. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  2. 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 ...

  3. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  4. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

  5. [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 ...

  6. [LeetCode] Group Shifted Strings 群组偏移字符串

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  7. [LeetCode] Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. [LeetCode] Multiply Strings 字符串相乘

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. 使用strings查看二进制文件中的字符串

    使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...

  10. LeetCode 205 Isomorphic Strings

    Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...

随机推荐

  1. linux查看磁盘信息

    linux查看磁盘挂载信息:df -hlinux查看文件夹大小:sudo du -h --max-depth=1

  2. UITableView 自带编辑删除 自己定义button

    一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark   tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...

  3. soap的调用方式

    1.方式1    url:http://localhost:3651/recruit/index.asmx?WSDL post 内容: <soapenv:Envelope xmlns:soape ...

  4. PHP 7.1.5编译安装

    1. 安装基础组件 yum install -y libxml2 libxml2-devel bzip2 bzip2-devel curl-devel libjpeg libjpeg-devel li ...

  5. Ubuntu NDK配置与JNI demo

    NDK配置 1.下载最新版本NDK(android-ndk-r9d-linux-x86_64.tar.bz2) 下载网页:http://developer.android.com/tools/sdk/ ...

  6. 深入理解spring国际化

    深入理解spring国际化 转自http://blog.csdn.net/ethan_fu/article/details/45621337

  7. java 重定向和转发(转载)

    jsp中result的默认类型为dispatcher. dispatcher:与<jsp:forward page=""/>效果相同 redirect:与respons ...

  8. 初步探讨WPF的ListView控件(涉及模板、查找子控件) - GavinJun

    本文结合模板的应用初步介绍ListView的应用 一.Xaml中如何建立数据资源 大部分数据都会来自于后台代码,如何Xaml同样的建立数据源呢?比如建立一个学生List: 首先引入命名空间: xmln ...

  9. 从TFS中的现有项目复制一份作为新项目,导致提交的服务器无法加载

    解决方案: 1.编辑 .csproj文件,改为自己的名字 2.取消解绑

  10. Java类加载器(死磕 1-2)

      Java类加载器(  CLassLoader ) 死磕 1.2:  导入 & 类加载器分类 本小节目录 1.导入 1.1. 从class文件的载入开始 1.2. 什么是类加载器 2. JA ...