CodeForces 544A
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.
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.
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.
1
abca
YES
abca
2
aaacas
YES
aaa
cas
4
abc
NO
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
做简单题目,慢慢来,想快点,写好点
#include <cstring>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std; int main()
{
//freopen("in.txt", "r", stdin);
int nstr; while(scanf("%d", &nstr) != EOF)
{
getchar();
char str[];
bool vis[];
gets(str);
int len = strlen(str);
memset(vis, false, sizeof(vis)); set<char> s; int p = ;
s.insert(str[]);
++p;
vis[] = true;
if(p != nstr)
{
for(int i = ; i != len; ++i)
{
if(s.find(str[i]) == s.end() && p < nstr)
{
s.insert(str[i]);
++p;
vis[i] = true;
}
}
} if(p < nstr)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
for(int i = ; i != len; ++i)
{
if(vis[i] == true)
{
putchar(str[i]);
int j = i+;
while(vis[j] == false && j < len)
{
putchar(str[j]);
++j;
}
puts("");
}
}
}
}
return ;
}
CodeForces 544A的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- JQ001-认识jQuery 和 JQ002-jQuery选择器
JQ001-认识jQuery jQuery环境配置:将jQuery.js文件引入到html页面中即可. 代码如下: <!DOCTYPE html> <html> <hea ...
- WIN7 + IIS7 Service Unavailable HTTP Error 503. The service is unavailable.
在win7上开启IIS功能,进行网站发布. 但是开启IIS之后,打开默认网站都打不开,显示 Service Unavailable HTTP Error 503. The service is una ...
- ecshop 后台 审核功能
有三个关键文件 html文件<img src="images/{if $vo.is_check}yes{else}no{/if}.gif" onclick="lis ...
- 【09-03】java泛型学习笔记
静态方法的泛型 /** * @description 静态方法的泛型无法使用类定义的泛型,因为类在实例化时才确定具体的泛型类,因此静态方法要使用泛型需要使用泛型方法的方式 */ public clas ...
- 精选9个值得学习的 HTML5 效果【附源码】
这里精选了一组很酷的 HTML5 效果.HTML5 是现 Web 开发领域的热点, 拥有很多让人期待已久的新特性,特别是在移动端,Web 开发人员可以借助 HTML5 强大功能轻松制作各种交互性强.效 ...
- CF#138 div 1 A. Bracket Sequence
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...
- MySQL字段自增长AUTO_INCREMENT的学习笔记
1.创建表时指定AUTO_INCREMENT自增值的初始值(即起始值): CREATE TABLE XXX (ID INT(5) PRIMARY KEY AUTO_INCREMENT) AUTO_IN ...
- jvm七种垃圾收集器
JVM_七种垃圾收集器介绍 本文中的垃圾收集器研究背景为:HotSpot+JDK7 一.垃圾收集器概述 如上图所示,垃圾回收算法一共有7个,3个属于年轻代.三个属于年老代,G1属于横跨年轻代和年老 ...
- c++笔记整理
一:导读 假设编写了一个C++程序,如何让他允许起来呢,这取决于计算机环境和所使用的C++编译器. 1.使用文本编辑器编写程序,并将其保存在文档中,====此就是源代码 2.编译源代码,编译过程就意味 ...
- 在 IIS 6 和 IIS 7中配置Https,设置WCF同时支持HTTP和HTPPS,以及使用HttpWebRequest和HttpClient调用HttpS
IIS 7 ,给IIS添加CA证书以支持https IIS 6 架设证书服务器 及 让IIS启用HTTPS服务 WCF IIS 7中配置HTTPS C#利用HttpWebRequest进行post请求 ...