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:用二进制表示放的数字,然后状 ...
随机推荐
- 一名网工对Linux运维的一次经历
我是一名名副其实的网络工程师,驻场于某市数字化城乡管理指挥中心(简称数字城管),主要针对中大型网络系统,路由.交换机.存储.小型机等设备进行维护,主要工作职责主要分为两种: 对网络系统中的网络设备(路 ...
- HDU-2087-KMP-水题
纯KMP #include <cstdio> #include <algorithm> #include <cstring> #include <ctype. ...
- 自学Linux Shell19.2-gawk程序高级特性
点击返回 自学Linux命令行与Shell脚本之路 19.2-gawk程序高级特性 linux世界中最广泛使用的两个命令行编辑器: sed gawk 1. gawk使用变量 编程语言共有的特性是使用变 ...
- 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix之路15.2 Zabbix数据库表结构简单解析-Items表 Items表记录了i ...
- HTML for android 移动小球
<html> <head> <title>球</title> <style type="text/css"> .test ...
- A1056. Mice and Rice
Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...
- 移动UI布局设计原则(一)
学习笔记1 Learning notes one 移动UI布局设计的布局原则 Layout Principles of Mobile UI Layout Design 移动UI视觉交互设计法则 Des ...
- caffe 错误
一些caffe错误 训练时很快梯度爆炸,loss猛增至nan 如果找不到数据上的原因的话,可以怀疑caffe框架有问题,换用其它版本试试.比如我遇到的问题是在训练时使用了Accuracy层,而该层的实 ...
- JasperReport 中踩过的坑
Mac Book Pro 10.13.6Jaspersoft Studio community version 6.6.9JDK 8 安装 Jaspersoft Studio Jasper Rep ...
- dijkstra 的优先队列优化
既然要学习算法,就要学习到它的精髓,才能够使用起来得心应手. 我还是远远不够啊. 早就知道,dijkstra 算法可以用优先队列优化,我却一直不知道该怎样优化.当时,我的思路是这样的:假设有n个顶点, ...