【无标题】

#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;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值