确实抽象,我建议直接sort
by HH_yst @ 2024-04-19 09:04:21
感觉是
```cpp
for(ls=a[m];m!=n-1;m++){
if(ls<a[m+1])
ls=ls;
else ls=a[m+1];
}
```
这里
by HH_yst @ 2024-04-19 09:07:42
好像不是
by HH_yst @ 2024-04-19 09:10:15
@[bjx897](/user/652508)
```cpp
q==0
```
应该是这里,但是我还是建议重构,你的马蜂好奇怪啊
by HH_yst @ 2024-04-19 09:23:07
建议这样:
```cpp
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#define int long long
#define N 1000006
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
return;
}
int n,a[N],k,ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
n=read();k=read();
for(int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);
a[n+1]=3452343456;
for(int i=2;i<=n+1;i++){
if(a[i]!=a[i-1])k--;
if(k==0){
write(a[i-1]);
return 0;
}
}
puts("NO RESULT");
return 0;
}
```
虽然我用c++但是你先排个序嘛
by HH_yst @ 2024-04-19 09:27:59
@[HH_yst](/user/410655) 感谢,抽象的原因是想只靠大学教的基础语句写的原因……
by bjx897 @ 2024-04-19 10:14:03
awa
by HH_yst @ 2024-04-20 22:05:16