60!!!

P1923 【深基9.例4】求第 k 小的数

jiangjinke @ 2023-07-03 22:04:05

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,t;
    cin>>n>>t;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<a[t];
    return 0;
}

by xuzihao123 @ 2023-07-03 22:12:27

@jiangjinke


by xuzihao123 @ 2023-07-03 22:17:35

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,t;
    scanf("%d %d",&n,&t);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    cout<<a[t];
    return 0;
}

by Terrible @ 2023-07-03 22:20:00

你猜为什么要有nth_element这个函数?


by jiangjinke @ 2023-07-07 14:43:53

@[xuzihao123](/user/946929) 
谢谢!
主要不会写scanf和printf

|