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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- [NHibernate]存储过程的使用(三)
目录 写在前面 文档与系列文章 查询 总结 写在前面 前面的文章介绍了在nhibernate中使用存储过程进行增删改的操作,当然查询也是可以的,在nhibernate中也可以执行任意的存储过程.本篇文 ...
- css3动画简介以及动画库animate.css的使用
在这个年代,你要是不懂一点点css3的知识,你都不好意思说你是个美工.美你妹啊,请叫我前端工程师好不好.呃..好吧,攻城尸...呵呵,作为一个攻城尸,没有点高端大气上档次的东西怎么能行呢,那么css3 ...
- windows7安装GitBash和GitGui
安装很简单,搜索安装就行. 配置: 1.$ ssh-keygen -t rsa -C "your_email@youremail.com" 将"your_email@yo ...
- func_get_arg、func_get_args、func_num_args实现PHP伪重载
今天在看书的时候,发现书上有这么一条:函数重载的替代方法——伪重载 确实,在PHP中没有函数重载这个概念,让很多时候我们无法进行一些处理,甚至有时候不得不在函数后面定义好N个参数在看到了func_ge ...
- 超全的web开发工具和资源
首页 新闻 产品 地图 动态 城市 帮助 论坛 关于 登录 注册 · 不忘初心,继续前进,环境云V2接口正式上线 · 环境云测点地图全新改版 · 祝福各位环境云用户中秋快乐! 平台信息 培训互动 ...
- resize
resize 属性规定是否可由用户调整元素尺寸. resize: none|both|horizontal|vertical; none:用户无法调整元素的尺寸. 比较常用 both:用户可 ...
- NSCache
今天在优化的时候,用了NSCache,感觉没什么两样(视觉上).按理内存缓存,怎么也比从硬盘读取的要快.. dispatch_async(dispatch_get_global_queue(, ), ...
- 【SCOI2005】 最大子矩阵 BZOJ 1084
Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. Input 第一行为n,m,k(1≤n≤100,1≤m≤2 ...
- ASP.NET正则表达式(URL,Email)
public static bool IsUrl(this string str) { if (str.IsNullOrEmpty()) return fal ...
- Python~recursive function递归函数
尾递归实现循环 def fact(n): if n==1: return 1 else : return n * fact(n-1) raw_input() 字符而非数字 unsupported op ...