题目1473: A Huge Wave Of Professors Is Approaching!
输入
The input consists one test case.The first line contains an integer n(n<=300),which means the number of students.The second line contains n integers means the exam results of these n students.As you know,full mark is 500.The third line contains an integer m,which means the number of professors.Then follows m lines,each line contains two integer,A and B(0<=A,B<=500),which means professor's recruitment criteria.
输出
For each test case, you should output m lines with the recruited student's exam result.If no student meet professor's requirement,you should output -1.
样例输入
7
306 304 389 342 343 355 302
4
350 390
380 400
307 303
500 400
样例输出
389
-1
306
-1
提示 [+]
*** 提示已隐藏,点击上方 [+] 可显示 ***
来源
2013年浙江大学复试机试模拟题
#include<stdio.h>int n;void run(){ int i,m,max,min,j,k,answer,a[111111]; for(i=0;i<n;i++) scanf("%d",&a[i]); scanf("%d",&m); for(j=1;j<=m;j++) { k=-1; answer=-1; scanf("%d%d",&max,&min); if(max<min)//A与B的大小关系不确定 { i=max; max=min; min=i; } for(i=0;i<n;i++)//如果找不到符合条件的学生,answer保持原值-1 if(a[i]>=min&&a[i]<=max)//符合条件的学生,注意等号 if(a[i]>answer) { k=i;//记录这个学生的位置,以便清除 answer=a[i]; } printf("%d\n",answer); if(k>-1) a[k]=-1;//清除被选中的学生 }}int main(){ scanf("%d",&n); run(); return 0;}