Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Counting Rock samples

+1 vote
asked Jul 26, 2018 by ravindra reddy (340 points)

Counting Rock samples

Problem Description

Juan Marquinho is a geologist and he needs to count rock samples in order to send it to chemical laboratory. He has a problem: The laboratory only accepts rock samples by a range of its size in ppm (parts per million).

Juan Marquinho receives the rock samples one by one and he classifies the rock samples according the range of the laboratory. This process is very hard because the rock samples may be in millions.

Juan Marquinho needs your help, your task is develop a program to get the number of rocks of a given range of size.

Constraints

10 <= S <= 10000

1 <= R <= 1000000

1<=size of Sample <= 1000

Input Format

An positive Integer S (the number of rock samples) separated by a blank space, and a positive Integer R (the number of ranges of the laboratory);

A list of the sizes of S samples (in ppm), as positive integers separated by space

R lines where ith line containing two positive integers, space separated, indicating the minimum size and maximum size respectively of the ith range.

Output

R lines where ith line containing a single non-negative integer indicating the number of samples in the ith range.

Explanation

Example 1

Input

10 2 345 604 321 433 704 470 808 718 517 811 300 350 400 700

Output

2

4

Explanation

There are 10 sampes (S) and 2 ranges ( R ). The samples are 345, 604,…811. The ranges are 300-350 and 400-700. There are 2 samples in the first range (345 and 321) and 4 samples in the second range (604, 433, 470, 517). Hence the two lines of the output are 2 and 4.

Example 2

Input

20 3

921 107 270 631 926 543 589 520 595 93 873 424 759 537 458 614 725 842 575 195

1 100

50 600

1 1000

Output

1

12

20

Explanation

There are 20 samples, and 3 ranges. The samples are 921, 107 … 195. The ranges are 1-100, 50-600 and 1-1000. Note that the ranges are overlapping. The number of samples in each of the three ranges are 1, 12 and 20 respectively. Hence the three lines of the output are 1, 12 and 20.

3 Answers

0 votes
answered Jul 27, 2018 by SELVI MANOHARAN
#include<stdio.h>

#include<conio.h>

void main()

{

 int n[100],m[100],k[100],i,t,c[100],b;

 clrscr();

 scanf("%d",&t);

 for(i=0;i<t;i++)

 {

     scanf("%d%d%d",&n[i],&k[i],&m[i]);

 }

 for(i=0;i<t;i++)

 {

     c[i]=1;

     n[i]=n[i]+k[i];

     b=m[i];

     while(n[i]!=m[i])

     {

if(n[i]>m[i])

{

     m[i]+=b;

c[i]++;

}

else

{

     n[i]=n[i]+k[i];

}

 } }

  for(i=0;i<t;i++)

  {

     printf("%d\n",c[i]);

 }

    getch();

}
0 votes
answered Jun 28, 2019 by suri
#include<stdio.h>
int main()
{
    int a[100],b[100][100],n,i,r,j,k;
    scanf("%d %d",&n,&r);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<r;i++)
    {
        for(j=0;j<=1;j++)
        {
            scanf("%d",&b[i][j]);
        }
    }
    k=0;
    for(i=0;i<r;i++)
    {
        int count=0;
        for(j=0;j<n;j++)
        {
            if(a[j]>=b[i][k]&&a[j]<=b[i][k+1])
        {
            count++;
        }
        }
        printf("%d\n",count);
    }
    return 0;
    
}
0 votes
answered Jul 3, 2019 by Naveen Kumar Maddineni
#include<stdio.h>

int main()

{

int s,r;

scanf("%d%d",&s,&r);

int a[s],b[r*2],c[2*r],i,j;

for(i=0;i<s;i++)

scanf("%d",&a[i]);

for(i=0;i<2*r;i++)

{

scanf("%d",&b[i]);

c[i]=0;

}

for(i=0;i<s;i++)

{

for(j=0;j<2*r-1;j+=2)

{

if(a[i]>=b[j]&&a[i]<=b[j+1])

{

c[j]=c[j]+1;

break;

}

}

}

for(i=0;i<2*r-1;i+=2)

printf("%d\n",c[i]);

return 0;

}
commented Jul 8, 2019 by anonymous
only one test case is working the second sample testcase is not working
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...