Initiate Luogu
This commit is contained in:
44
Luogu/P1138.cpp
Normal file
44
Luogu/P1138.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main() {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
int a[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
bool flag = false;
|
||||
while (flag == false)
|
||||
{
|
||||
int js = 0;
|
||||
for(int i = 0; i < n-1; i++){
|
||||
if(a[i] > a[i+1]){
|
||||
swap(a[i],a[i+1]);
|
||||
js++;
|
||||
}
|
||||
}
|
||||
if (js == 0)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; i < n - 1 ; i++) {
|
||||
if(a[i] == a[i+1]){
|
||||
a[i] = -1;
|
||||
}
|
||||
}
|
||||
int js = 0;
|
||||
int b[n]={0};
|
||||
for(int i = 0; i < n; i++){
|
||||
if(a[i] != -1){
|
||||
b[js] = a[i];
|
||||
js++;
|
||||
}
|
||||
}
|
||||
if(k<js) cout<<b[k-1]<<endl;
|
||||
else cout<<"NO RESULT"<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user