传送门

题目

You are given a string s. Among the different substrings of s, print the K-th lexicographically smallest one.

A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = ababcabab and ababc are substrings of s, while acz and an empty string are not. Also, we say that substrings are different when they are different as strings.

Let X=x1x2…xn and Y=y1y2…ym be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or xj>yj where j is the smallest integer such that xjyj.

Constraints

  • 1  |s|  5000
  • s consists of lowercase English letters.
  • 1  K  5
  • s has at least K different substrings.

Partial Score

  • 200 points will be awarded as a partial score for passing the test set satisfying |s|  50.

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

题目大意

给你一个字符串s,求它字典序第k大的字串

分析

因为k<=5,所以我们可以枚举字串的起始点和长度,以为长度小,我们把整个字串转化成数字然后排序即可,注意长度不满k的字串在末尾要补零

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long a[110000];
map<long long,bool>app;
int cnt;
long long go(string s,int le,int ri){
    int i,j,k;
    long long res=0;
    for(i=le;i<=ri;i++)
        res=res*100+(s[i]-'a'+1);
    for(i=ri-le+2;i<=5;i++)    
        res*=100;
    return res;
}
int main()
{   int n,m,i,j,k;
    string s;
    cin>>s;
    n=s.length();
    cin>>k;
    for(i=0;i<n;i++)
        for(j=i;j<=min(i+k,n-1);j++){
            long long res=go(s,i,j);
            if(!app[res]){
                a[++cnt]=res;
                app[res]=1;
            }
        }
    sort(a+1,a+cnt+1);
    char c[110];
    cnt=0;
    while(a[k]){
        if(a[k]%100)c[++cnt]=(a[k]%100-1)+'a';
        a[k]/=100;
    }
    for(i=cnt;i>0;i--)
        cout<<c[i];
    return 0;
}

ARC097C K-th Substring的更多相关文章

  1. LeetCode第[5]题(Java):Longest Palindromic Substring 标签:String、动态规划

    题目中文:求最长回文子串 题目难度:Medium 题目内容: Given a string s, find the longest palindromic substring in s. You ma ...

  2. sql 取汉字首字母

    )) ) --用于加密 --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = ...

  3. sql 函数 汉字转拼音

    GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2017/1/4 10:53:49 ******/ SET A ...

  4. Pjax调用

    $.pjax({container:'#content_center',url:href,data:data}); $(document).on('pjax:send', function() {// ...

  5. 都别说工资低了,我们来一起写简单的dom选择器吧!

    前言 我师父(http://www.cnblogs.com/aaronjs/)说应当阅读框架(jquery),所以老夫就准备开始看了 然后公司的师兄原来写了个dom选择器,感觉不错啊!!!原来自己从来 ...

  6. Leetcode: Encode String with Shortest Length && G面经

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  7. JAVA时间格式转换大全

    import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...

  8. Spark中常用工具类Utils的简明介绍

    <深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...

  9. sql拼音简写函数

    USE [HotelDB]GO /****** Object: UserDefinedFunction [dbo].[fn_GetPy] Script Date: 2016/1/4 13:29:13 ...

  10. SQL将用户表中已存在的数据所有姓名(汉字)转换为拼音首字母

    实现方法: --函数 Create function [dbo].[fn_GetPy](@str nvarchar(4000)) returns nvarchar(4000) --用于加密 --WIT ...

随机推荐

  1. 【leetcode刷题笔记】Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  2. Python 3 并发编程多进程之进程与线程

    Python 3 进程与线程 进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的 ...

  3. nginx配置大全

    nginx配置大全

  4. JAVA事件监听机制与实现

    事件监听机制的实现:参考图:事件模型_ActionEvent 为了节省资源,系统无法对某个事件进行实时的监听.故实现的机制是当发生某个事件后,处理代码将被自动运行,类似钩子一般.(回调函数) 事件有许 ...

  5. /etc/init.d目录和/etc/rc.local脚本

    一.关于/etc/init.d 如果你使用过Linux系统,那么你一定听说过init.d目录.这个目录到底是干嘛的呢?它归根结底只做了一件事情,但这件事情非同小可,是为整个系统做的,因此它非常重要.i ...

  6. linux学习系列二

    vim是由vi发展而来,具有语法高亮显示,多视图编辑,代码折叠,支持插件等功能,vim成为了linux发行版本的标配. 1. vim工作模式 1. 普通模式:实现基本的光标移动和大量的快捷操作 2. ...

  7. Oracle数据库操作语言(DML)

    --insert添加语句 insert into table_name(column_name,column_name,...) values (data1,data2,...); --通过表添加数据 ...

  8. python函数的参数匹配

    版本:一般用python2.7.6 python3.4.3会标注 1.不可变对象(整数.字符串)通过对象引用进行传递,在函数内部不可改变. >>> def f(a): ... a=1 ...

  9. html5 tab横向滚动,无滚动条(transform:translate)

    html5 横向滚动,用到了 touchstart.touchmove.touchend 控制修改transform:translate属性;[手机端或者浏览器模拟手机模式才有效果] [转载请注明出处 ...

  10. flex 和bison的安装和使用

    1.在ubutu上安装 yacc的命令: sudo apt-get install flex bison flex:词法分析器 flex是一个词法分析器.用来将一个.l文件生成一个.c程序文件.即生成 ...