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
  • 相关阅读:
    域名交易网
    android canvas 二
    android 获取当前时间
    loadrunner 面向目标的场景load Generator 连接 失败
    开发平台
    java 调用 bat 如果里面用了第三方命令 dos 窗口没有关闭 解决方法
    Socket网络框架 MINA
    JQuery引用
    Jmeter
    android 获取 service 信息
  • 原文地址:https://www.cnblogs.com/xz816111/p/4506925.html
Copyright © 2011-2022 走看看