F - Set of Strings
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.
Examples
Input
1
abca
Output
YES
abca
Input
2
aaacas
Output
YES
aaa
cas
Input
4
abc
Output
NO
Note
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
map<char,int >wakaka;
int a[1010];
int main()
{
int n;
cin>>n;
memset(a,0,sizeof(a));
string s;
cin>>s;
int len=s.size();
if(len<n)
{
cout<<"NO"<<endl;
}
else
{
a[0]=0;
int ans=0;
for(int i=0; i<len; i++)
{
if(wakaka[s[i]]==0)
{
ans++;
a[ans]=i;
}
wakaka[s[i]]++;
}
if(ans>=n)
{
cout<<"YES"<<endl;
for(int i=1; i<=ans; i++)
{
if(i==n)
{
for(int j=a[i]; j<len; j++)
{
cout<<s[j];
}
break;
}
for(int j=a[i]; j<a[i+1]; j++)
{
cout<<s[j];
}
cout<<endl;
}
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
F - Set of Strings的更多相关文章
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 构造
F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of ...
- Codeforces Round #598 (Div. 3) F. Equalizing Two Strings
You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters ...
- golang --strings 下常用函数api
1. func Compare(a, b string) int {} 比较返回一个按字典顺序比较两个字符串的整数.如果a == b则结果为0,如果a <b则结果为-1,如果a> b则结果 ...
- Equalizing Two Strings
F. Equalizing Two Strings 有几种情况可以直接判定结果: ① 字母对应个数不一样,可直接判NO ② 当不满足①时,如果有一个字母有2个及以上的个数,也可直接判YES ③ 当不满 ...
- float_array.go
) if err != nil { log.Fatalf("Could not parse: %s", s) ret ...
- JavaSE_List&Array_Java1.7
这里简单写了下List和Array的相互转换 package cn.rocker.collection.list; import org.junit.Test; import java.util.Ar ...
- 驳2B文 "我为什么放弃Go语言"
此篇文章流传甚广, 其实里面没啥干货, 而且里面很多观点是有问题的. 这个文章在 golang-china 很早就讨论过了. 最近因为 Rust 1.0 和 1.1 的发布, 导致这个文章又出来毒 ...
- [日常] Go语言圣经-错误,函数值习题
Go语言圣经-错误 1.panic异常.panic是来自被调函数的信号,表示发生了某个已知的bug 2.任何进行I/O操作的函数都会面临出现错误的可能 3.错误是软件包API和应用程序用户界面的一个重 ...
- AtCoder Regular Contest
一句话题解 因为上篇AGC的写的有点长……估计这篇也短不了所以放个一句话题解方便查阅啥的吧QwQ 具体的题意代码题解还是往下翻…… ARC 058 D:简单容斥计数. E:用二进制表示放的数字,然后状 ...
随机推荐
- 一本通1609【例 4】Cats Transport
1609:[例 4]Cats Transport 时间限制: 1000 ms 内存限制: 524288 KB sol:非常偷懒的截图了事 注意:只能猫等人,不能人等猫 对于每只猫,我们 ...
- BZOJ2662[BeiJing wc2012]冻结——分层图最短路
题目描述 “我要成为魔法少女!” “那么,以灵魂为代价,你希望得到什么?” “我要将有关魔法和奇迹的一切,封印于卡片之中„„” 在这个愿望被实现以后的世界里,人们享受着魔法卡片(Spe ...
- CentOS 显示历史执行过的命令以及用户历史命令缓存文件
1.history命令用于显示历史执行过的命令 执行 history命令能显示出当前用户在本地计算机中执行过的最近 1000 条命令记录. 如果觉得 1000 不够用,还可以自定义/etc/profi ...
- MT【207】|ax^2+bx+c|中判别式$\Delta$的含义
已知$a,b\in R^+,a+b=2$且对任意的$x\in R$,均有$|2x^2+ax-b|\ge|x^2+cx+d|$则$\dfrac{d-4c}{cd}$的最小值______ 提示:注意到$\ ...
- 获取外网出口ip
curl ifconfig.me 或 curl cip.cc
- 自学Aruba7.4-Aruba安全认证-MAC认证(web页面配置)
点击返回:自学Aruba之路 自学Aruba7.4-Aruba安全认证-MAC认证(web页面配置) 由于前三节已经讲述了3种如何web页面配置安全认证,MAC认证就不过多讲解重复的步骤. 步骤1 ...
- 架构师成长之路6.6 DNS服务器搭建(构建企业级DNS)
点击返回架构师成长之路 架构师成长之路6.6 DNS服务器搭建(构建企业级DNS) 采用LVS-DR模式负载均衡,多IDC,多套DNS集群,通过master-slave技术保证dns配置的一致性. 1 ...
- eclipse中用maven创建web项目
上一节中完成了本地的maven环境搭建,在eclipse中怎么创建一个maven项目呢 一.eclipse中配置maven环境 eclipse版本4.3 1.打开菜单Help->Eclipse ...
- 【BZOJ1826】[JSOI2010]缓存交换(贪心)
[BZOJ1826][JSOI2010]缓存交换(贪心) 题面 BZOJ 洛谷 题解 当缓存不满显然直接放进去,满了之后考虑拿走哪一个.不难发现拿走下一次出现时间最晚的那个一定不会更差. 那么用一个堆 ...
- 【bzoj4818】 Sdoi2017—序列计数
http://www.lydsy.com/JudgeOnline/problem.php?id=4818 (题目链接) 题意 一个长度为$n$的序列,每个元素是不超过$m$的正整数,且这$n$个数的和 ...