聪明的小李

Description

小李的识记能力非常强,一列数他一看就知道最大的是哪个数,这个数在原数列中的位置。现在的问题是给定一个各不相同的正整数数列,要你找出第K大的数是多少,并指出该数在原数列中的位置。

Input

共有三行,第一行是一个正整数N,表示原数列共有N个数,第二行是N个正整数,表示原数列中的每一个数。第三行是一个正整数,表示K的值。

Output

共二行,第一行是一个整数,表示原数列中第K大的数,第二行是一个正整数,表示第K大数在原数列中的位置。

Sample Input
5
34 12 55 42 90
3

Sample Output
42
4

.
.
.
.
.
程序:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct edge
{
	int x,bh;
} a[150];

bool cmp(edge xx,edge yy)
{
	return xx.x>yy.x;
}

int main()
{
	freopen("num.in","r",stdin);
	freopen("num.out","w",stdout);
	int n,k;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].x);
		a[i].bh=i;
	}
	scanf("%d",&k);
	sort(a+1,a+n+1,cmp);
	printf("%d\n%d",a[k].x,a[k].bh);
	fclose(stdin);
	fclose(stdout);
	return 0;
}
posted @ 2019-05-01 10:21  银叶草  阅读(137)  评论(0编辑  收藏  举报
Live2D