题意:
读入一个串..输出其第k大的子串
题解
直接用优先队列暴力..
Program:
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
#include<stack>
#include<queue>
#include<algorithm>
#define oo 1000000007
#define ll long long
#define MAXN 100005
using namespace std;
struct node
{
string s;
int t;
bool operator <(node a) const
{
return a.s<s;
}
}h,p;
char str[MAXN];
priority_queue<node> myqueue;
void judge(int num)
{
int i,len=strlen(str);
while (!myqueue.empty()) myqueue.pop();
for (i=0;i<len;i++)
{
h.t=i,h.s=str[i];
myqueue.push(h);
}
while (!myqueue.empty())
{
h=myqueue.top();
myqueue.pop();
num--;
if (!num) { cout<<h.s<<endl; return; }
p.t=h.t+1;
if (p.t==len) continue;
p.s=h.s+str[p.t];
myqueue.push(p);
}
printf("No such line.\n");
return;
}
int main()
{
gets(str);
int x;
scanf("%d",&x);
judge(x);
return 0;
}