How many pizzas ?

PROBLEM :

You are given two stacks of pizzas, but you can only take those pizzas from one stack that are also present in the other stack, in the same order, the pizzas that you can take need not be continuous.

Print the maximum amount of pizzas that you can take. (You can only take pizzas from one of the two stacks)

INPUT
The first line contains only one integer, t, the number of test cases.

For each case, there are two lines:
Line 1: 10 integers, which represent radii of the pizzas in the first stack.
Line 2: 10 integers, each of which represent radii of pizzas in the second stack.

OUTPUT:
For each case, a single integer that gives the maximum amount of pizzas that you can take.

Constraints:
1<=T<=100
1<=radii<=1000

Example:

Input:
1
891 424 945 741 897 514 692 221 678 168
702 952 221 614 69 753 821 971 318 364

Output:
1

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
void bubble(int []) ;
int main()
 {
int t,a[10],b[10],i,j,count  ;
cin>>t ;
while(t--)
{
   for(i=0;i<10;i++)
       cin>>a[i] ;
     
   for(i=0;i<10;i++)
       cin>>b[i] ;
     
   bubble(a) ;
   bubble(b) ;
   count=0 ;
   i=0;
   j=0 ;
 
   while(i!=10&&j!=10)
   {
       if(a[i]==b[j])
           count++ ;
     
       if(a[i]<b[j])
           i++ ;
       else
           j++ ;
   }
  cout<<count<<endl ;
}
return 0;
}

void bubble(int a[])
{
    int i,j,temp ;
   
    for(i=0;i<9;i++)
    {
        for(j=0;j<9-i;j++)
        {
            if(a[j]>a[j+1])
            {
                temp=a[j] ;
                a[j]=a[j+1] ;
                a[j+1]=temp ;
            }
        }
    }
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )