• A


    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    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

    Input
    1
    abca
    Output
    YES
    abca
    Input
    2
    aaacas
    Output
    YES
    aaa
    cas
    Input
    4
    abc
    Output
    NO

    Hint

    In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}.

    题意:

    给你k和一个字符串q,求能否将q分为k份且每一份的首字符各不相同。

    可用map来筛选不同的字母的个数,可分为k段则至少有k个不同的字母。输出时再用map记录以用过的首字母。

    附AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<map>
     6 #include<algorithm>
     7 using namespace std;
     8 
     9 int main(){
    10     string s,a;
    11     int k,lens,lenm;
    12     cin>>k>>s;
    13     int t=1,temp=0,ans=0;
    14     map<char,int> m;
    15     lens=s.size();
    16     for(int i=0;i<lens;i++){
    17         m[s[i]]=1;
    18     }
    19     lenm=m.size();
    20     a[0]=s[0];
    21     if(lens>=k&&lenm>=k){
    22         m.clear();
    23         cout<<"YES"<<endl;
    24             for(int i=0;i<lens;i++){
    25                 if(m[s[i]]==0 && temp<k){
    26                 if(temp) cout<<endl;
    27                 temp++;
    28             }
    29             m[s[i]]++;
    30             cout<<s[i];
    31             }
    32     }
    33     else{
    34         cout<<"NO"<<endl;
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    第二阶段个人总结7
    第二阶段个人总结6
    第十七周进度报告
    个人总结
    十六周进度报告
    人月神话阅读笔记3
    十五周进度报告
    十四周进度报告
    人月神话阅读笔记2
    购买图书
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5705368.html
Copyright © 2020-2023  润新知