# include<iostream># include<algorithm>using namespacestd;intJishu (intA[],intNintkey) { intleft =0, right = N1, mid,flag=0; while(left<=Right ) {Mid= left + (left + right)/2 ; if(Key = =A[mid]) {Flag=1; Break; } Else if(Key <A[mid]) { Right= Mid-1; } Else{ Left= Mid +1; } } intCount =0; if(flag==0) { returncount; } Else { for(inti=mid;i<n;i++) { if(a[i]==key) {Count++; } Else { Break; } } for(inti=mid-1; i>=0; i--) { if(a[i]==key) {Count++; } Else { Break; } } returncount; }}intMain () {intn,k,i,j; CIN>>N; intA[n]; for(i=0; i<n;i++) {cin>>A[i]; } sort (A,a+N); CIN>>K; intC[j]; for(i=0; i<k;i++) {cin>>B[i]; if(I! = k1) {cout<<jishu (A,n,b[i]) <<" "; } Else{cout<<Jishu (A,n,b[i]); } } return 0;}
This requires reading the scores of n students and outputting the number of students for a given score.
Input format:
The input gives a positive integer n of not more than 105 in line 1th, which is the total number of students. The next 1 lines give the percentile integer scores of the N students, separated by a space. The last 1 lines give the number of points to query K (a positive integer not more than N), followed by a k fraction, separated by a space.
Output format:
The number of students who scored equal to the specified score is given in a row in the order of inquiry, separated by a space, but no extra space at the end of the line.
Input Sample:
1060 75 90 55 75 99 82 90 75 503 75 90 88
Sample output:
3 2 0
PAT1038 (two run timeout not resolved