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
  • 相关阅读:
    程序员必须知道的10大基础实用算法及其讲解
    6 Java Exceptions that Haunts a Newbie Java Developer(Java菜鸟6种常见的异常)
    在线学习Java免费资源推荐(来自:importnew)
    Oracle触发器
    Oracle性能分析工具介绍及使用
    开口大数据闭口高并发,你们都是怎么回答
    Http中Get/Post请求区别
    快速排序算法
    MAG EF查询增加指定索引功能
    WEB传参
  • 原文地址:https://www.cnblogs.com/xz816111/p/4506925.html
Copyright © 2011-2022 走看看