#include <iostream>
#include <string>
typedef struct MyString* StrPoint;
struct MyString{
char data;
StrPoint Link;
};
class Array1{
private:
StrPoint Front,Rear;
int Length,MaxInit,MaxLength;
public:
Array1(){
this->Length=0;
this->Front=(StrPoint)malloc(sizeof(struct MyString));
this->Rear=Front;
this->Front->Link=NULL;
this->Length=0;
}
void FindMaxSequence(){
if(this->Front->Link==NULL){
std::cout<<"NULL\n";
return;
}
StrPoint InitP=this->Front;
this->MaxInit=0;
this->MaxLength=0;
int TempInitNum=0;
int i=0;
for(i=this->MaxInit;i<this->Length;i++){
if(InitP->data>=48&&InitP->data<=57){
TempInitNum++;
if(TempInitNum>this->MaxLength){
this->MaxLength=TempInitNum;
this->MaxInit=i-TempInitNum;
}
} else{
TempInitNum=0;
}
InitP=InitP->Link;
}
std::cout<<this->MaxInit+1<<" "<<this->MaxLength<<"\n";
}
StrPoint InputString(){
char ch1;
ch1=getchar();
while(ch1!='\n'){
this->Rear->data=ch1;
StrPoint NewStrP=(StrPoint)malloc(sizeof(struct MyString));
NewStrP->Link=NULL;
this->Rear->Link=NewStrP;
this->Rear=NewStrP;
ch1=getchar();
this->Length++;
}
return this->Front;
}
void StrOutPutString(StrPoint P){
while (P->Link!=NULL){
std::cout<<P->data<<" \n";
P=P->Link;
}
}
int GetLength(){
return this->Length;
}
StrPoint GetFrontPoint(){
return this->Front;
}
};
class SequenceSaver{
public:
StrPoint P1;
StrPoint P2;
int StrNum;
SequenceSaver(){
P1=(StrPoint)malloc(sizeof(struct MyString));
P2=(StrPoint)malloc(sizeof(struct MyString));
P1->Link=NULL;
P2->Link=NULL;
StrNum=0;
}
void PrintNode(){
if(this->StrNum==0){
std::cout<<"NULL\n";
return;
}
for(;P1!=P2;P1=P1->Link){
std::cout<<P1->data;
}
}
};
void FindMaxSequence(Array1* arr1,Array1* arr2){
Array1* TempPmin=(arr1->GetLength()<arr2->GetLength())?arr1:arr2;
Array1* TempPmax=(arr1->GetLength()>arr2->GetLength())?arr1:arr2;
StrPoint StrMin=TempPmin->GetFrontPoint();
StrPoint StrMax=TempPmax->GetFrontPoint();
SequenceSaver* SePointer=new SequenceSaver();
SePointer->StrNum=0;
for(;StrMin->Link!=NULL;StrMin=StrMin->Link){
for(StrPoint StrMax2=StrMax;StrMax2->Link!=NULL;StrMax2=StrMax2->Link){
StrPoint StrMinCopy=StrMin;
StrPoint StrMaxCopy=StrMax2;
int StrNum=0;
while (StrMaxCopy->data==StrMinCopy->data){
StrNum++;
StrMaxCopy=StrMaxCopy->Link;
StrMinCopy=StrMinCopy->Link;
if((StrMaxCopy==NULL&&StrMinCopy==NULL)||(StrMaxCopy->data!=StrMinCopy->data)){
if(StrNum>SePointer->StrNum){
SePointer->StrNum=StrNum;
SePointer->P1=StrMin;
SePointer->P2=StrMinCopy;
}
break;
}
}
}
}
SePointer->PrintNode();
}
int main() {
Array1* arr1=new Array1();
Array1* arr2=new Array1();
arr2->InputString();
arr1->InputString();
FindMaxSequence(arr1,arr2);
}
#include<iostream>
using namespace std;
// 寻找中间值
int partition(int a[], int left, int right)
{
int i = left; //定义左标记
int j = right; //定义右标记
int x = a[left]; //中间值
while (i < j) //当最少两个值时进行执行
{
while (i < j && a[j] >= x)//右标记的值大于中间值时继续,判断前一位
{
j--;
}
if (i < j)
{
a[i++] = a[j]; //当a[j]的值小于x时,与a[i]对换位置
}
while (i < j && a[i] < x) //左标记的值小于中间值时继续,判断后一位
{
i++;
}
if (i < j)
{
a[j--] = a[i]; //当a[i]的值大于x时,与a[j]对换位置
}
}
a[i] = x; //找出最后的中间值
return i; //得到中间值位置
}
// 快速排序
void quicksort(int a[], int left, int right)
{
if (left < right)
{
int m = partition(a, left, right); //定义m为中间值位置
quicksort(a, left, m - 1); //对中间值左边排序
quicksort(a, m + 1, right); //对中间值右边排序
}
}
int main()
{
int n, k;
cin >> n >> k;
int a[10000];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
quicksort(a, 0, n - 1); //对所有值排序
cout << a[k - 1]; //输出第K个值
return 0;
}