Codeforces Round #302 (Div. 2) A. Set of Strings 水题
A. Set of Strings
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/544/problem/A
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
abca
Sample Output
abca
HINT
In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.
题意
把一个字符串能不能拆成N份,要求每一份的开头字母都不相同
题解:
统计一下有多少个不同的字母,如果小于n,那就直接输出no
否则就输出这些分开的字符串就好了~
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s;
map<char,int> H;
int flag[maxn];
int main()
{
int n=read();
int ans=;
cin>>s;
for(int i=;i<s.size();i++)
{
if(H[s[i]])
continue;
H[s[i]]=;
flag[ans]=i;
ans++;
}
if(ans<n)
{
puts("NO");
return ;
}
puts("YES");
for(int j=;j<n-;j++)
{
for(int i=flag[j];i<flag[j+];i++)
cout<<s[i];
cout<<endl;
}
for(int i=flag[n-];i<s.size();i++)
cout<<s[i];
cout<<endl;
}
Codeforces Round #302 (Div. 2) A. Set of Strings 水题的更多相关文章
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Round #384 (Div. 2) A. Vladik and flights 水题
A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...
随机推荐
- 64_n1
NFStest-2.1.5-0.fc26.noarch.rpm 16-Feb-2017 16:19 544018 NLopt-2.4.2-11.fc26.i686.rpm 13-Feb-2017 23 ...
- 21.Merge Two Sorted Lists---《剑指offer》面试17
题目链接:https://leetcode.com/problems/merge-two-sorted-lists/description/ 题目大意: 给出两个升序链表,将它们归并成一个链表,若有重 ...
- 005zabbix3.0报错记录
一.问题描述 在zabbix_server添加变量时,出现了以下的报错,
- linux系统定时任务设置
.使用at命令设置一次性定时任务 2.使用crontab设置周期性定时任务 1)cd /home 目录下,使用vi test.py创建文件,内容如下: #!/usr/bin/python#coding ...
- plsql实例精讲部分笔记
转换sql: create or replace view v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,mo ...
- ajax跨域的解决办法
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content ...
- 不需要打密码的sudo方法
Linux下频繁输入sudo很麻烦.如果你的账户已经是sudoer了,那么编辑/etc/sudoers,将 %sudo ALL=(ALL:ALL) ALL 修改为: %sudo ALL=(ALL) N ...
- PHP 分割字串 Function 的速度比較(substr/sscanf/preg_match)---substr最快!
固定長度的字串(假設是 06481a63041b578d702f159f520847f8), 要照固定格式做切割, 使用 PHP 要怎麼切會比較快? 註: 要將此字串切成 => 06 / 48 ...
- normalize.css阅读笔记
最近在被各种浏览器的CSS兼容折磨,所以看了看normalize的源代码来了解一些常见的浏览器间不一致的CSS渲染问题…… 源代码在这里 text-size-adjust 用法参见Apple的文档和M ...
- C# HTML 生成 PDF
原文出处:http://www.cnblogs.com/shanyou/archive/2012/09/07/2676026.html