PAT1038 (two run timeout not resolved

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.