zoukankan      html  css  js  c++  java
  • CF Set of Strings

    Set of Strings
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 1to 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 test(s)
    input
    1
    abca
    output
    YES
    abca
    input
    2
    aaacas
    output
    YES
    aaa
    cas
    input
    4
    abc
    output
    NO



     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <queue>
     5 #include <cstring>
     6 #include <string>
     7 #include <cstdlib>
     8 #include <cmath>
     9 #include <cctype>
    10 #include <map>
    11 #include <ctime>
    12 using    namespace    std;
    13 
    14 bool    VIS[30];
    15 int    main(void)
    16 {
    17     char    q[105];
    18     int    a,num;
    19     int    loc[105];
    20     num = 0;
    21 
    22     scanf("%d",&a);
    23     scanf("%s",q);
    24     for(int i = 0;q[i];i ++)
    25         if(!VIS[q[i]])
    26         {
    27             VIS[q[i]] = true;
    28             loc[num] = i;
    29             num ++;
    30         }
    31     loc[num] = strlen(q);
    32 
    33     if(num < a)
    34         puts("NO");
    35     else
    36     {
    37         puts("YES");
    38         for(int i = 0;i < a;i ++)
    39         {
    40             if(i == a - 1)
    41                 for(int j = loc[i];q[j];j ++)
    42                     printf("%c",q[j]);
    43             else
    44                 for(int j = loc[i];j < loc[i + 1];j ++)
    45                     printf("%c",q[j]);
    46             puts("");
    47         }
    48     }
    49 
    50     return    0;
    51 }
    View Code
  • 相关阅读:
    用javafx webview 打造自己的浏览器
    用cef Python打造自己的浏览器
    无需人工智能和机器学习,实现基于手势识别的计算器
    经常抱怨在公司学不到技术,学的技术没有使用场景怎么破?
    Linux相关集合
    个人博客注册,申请,美化流程
    Django注意知识点(二)
    Django 注意知识点(一)
    Java学习笔记(四)
    Java学习笔记(三)
  • 原文地址:https://www.cnblogs.com/xz816111/p/4506925.html
Copyright © 2011-2022 走看看