原题网址:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1002
Examination | ||||||
| ||||||
Description | ||||||
There are n classes in Mr Li’s grade.And each class have m student..The last examination’s ranked results have been finished.Now Mr Li wants to know the score of the student who got the kth place. | ||||||
Input | ||||||
Each test case have three integers n,m,k(1<=n<=10,1<=m<=100, 1<=k<=n*m) in the first line.Then,there are n lines,one line indicating the scores of one class.Each line contains m positive integers. | ||||||
Output | ||||||
For each test case,first print a line saying “Scenario #k”,where k is the number of the test case.Then,output one integer the score of student who are placed kth,in one line.Print a blank line after each test case,even after the last one. | ||||||
Sample Input | ||||||
2 4 4 90 87 98 59 78 67 88 99 | ||||||
Sample Output | ||||||
Scenario #1 88 |
题意就是给你n,m,k; 然后给你n*m个数,问其中第k大数是多少。
数据范围小,直接排序就可以解决了,注意输出格式。
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int m,n,k;
int Case = 1;
int gra[1009];
while(scanf("%d%d%d",&m,&n,&k) != EOF){
memset(gra,0,sizeof(gra));
int t = 0;
for(int i = 0;i < m;i++){
for(int j = 0;j < n;j++){
scanf("%d",&gra[t++]);
}
}
sort(gra,gra+m*n);
printf("Scenario #%d\n%d\n\n",Case++,gra[m*n-k]);
}
return 0;
}