Codeforces Beta Round #94 (Div. 1 Only)String

来源:互联网 发布:计算机二级vb培训 编辑:程序博客网 时间:2024/06/05 11:55

B. String
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day in the IT lesson Anna and Maria learned about the lexicographic order.

String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​.

The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string “aab”: “a”, “a”, “aa”, “ab”, “aab”, “b”). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn’t want to check all these strings. That’s why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

Input
The first line contains a non-empty string that only consists of small Latin letters (“a”-“z”), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

Output
Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying “No such line.” (without the quotes).

Examples
input
aa
2
output
a
input
abc
5
output
bc
input
abab
7
output
b
Note
In the second sample before string “bc” follow strings “a”, “ab”, “abc”, “b”.

题意:
给一个字符串,要求求出它的字典序为第k小的那个子串。

思路:
模拟这整个过程,先求出字典序最小的那个串,再求出字典序为第二小的那个串….最后求出字典序为k 的那个串

#include<cstdio>#include<string>#include<set>#include<iostream>using namespace std;typedef pair<string,int> data;set<data>se;string ss;int k;int main(){    while(cin>>ss>>k)    {        long long  n=ss.size();        if(k>n*(n+1)/2)        {            puts("No such line.");            continue;        }        se.clear();        string a[26]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};        for(int i=0;i<ss.size();i++)        {            se.insert(data(a[ss[i]-'a'],i+1));        }        k--;        while(k--)        {           data now=*se.begin();            se.erase(se.begin());            if(now.second==n)                continue;            now.first+=ss[now.second];            now.second++;            se.insert(now);        }        cout<<se.begin()->first<<endl;    }    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 螃蟹和柿子一起吃了怎么办 指甲上月牙没了怎么办 手指上月牙没了怎么办 指甲上没半月牙怎么办 电动车车牌被偷了怎么办 警察拖车拖坏了怎么办 6岁儿童牙疼怎么办 小白单车不退押金怎么办 光盘放笔记本电脑里读不出来怎么办 cd光盘读不出来怎么办 最近脸干的不行怎么办 脸感觉干的不行怎么办 新生儿睡觉黑白颠倒了怎么办 婴儿吐水和奶花怎么办 刚刚出生的宝宝拉肚子怎么办 刚出生的婴儿拉肚子怎么办 新生儿5天拉稀水怎么办 10个月孩子拉肚子怎么办 不满月的宝宝拉肚子怎么办 一周岁宝宝发烧腹泻呕吐怎么办 6个月宝宝37度怎么办 1岁宝宝发烧37.2怎么办 新生儿发烧37度3怎么办 两个月宝宝抵抗力差怎么办 6月宝宝着凉拉稀怎么办 六个月的宝宝拉肚子怎么办 衣服颜色太深了怎么办 一多半宝宝爱喝水不爱吃饭怎么办 十个月宝宝不爱吃饭怎么办 十个月宝宝突然不爱吃饭怎么办 二十个月宝宝不爱吃饭怎么办 十个月的宝宝不爱吃饭怎么办 6年级学生数学差怎么办 打印机打不出来就是一张白纸怎么办 wps表格下拉数字不递增怎么办 wps表格圈怎么打出来怎么办 手表固定圈掉了怎么办 起来觉得头晕头胀怎么办? 孩子不好好写作业怎么办 孩子考试考差了怎么办 孩子计算题马虎大意怎么办