PROBLEM LINK:
Author: Shubham Goswami
Tester: Abhijeet Trigunait
Editorialist: Shubham Goswami
DIFFICULTY:
EASY
PREREQUISITES:
Array
PROBLEM:
Chef, the event manager of his college . He has been assigned to count the total number of teams taking part in a particular contest . A team consists of two students . Chef decides to do a lottery for team formation . Each student has to choose a ticket from the collection of tickets given and two students with matching ticket numbers can make a pair for a team .
Given N number of tickets and an array A[ ] of size N with ticket numbers .
Chef is busy handling other activities for the events so he needs your help . You have to count the total number of teams .
Note:- Each and every student can make a pair only once .
EXPLANATION:
This is the simple array frequency problem in which you have to just count the occurrence of a specific ticket number and count the number of pairs of a matching ticket number . So to count the frequency take an array of size 100 . Ticket numbers will not be greater than 10^2 (refer CONSTRAINTS). So taking an array a[100] for counting the number of times a particular ticket number occurs . Initially setting up all ticket numbers occurs 0 times. Ticket number refers to index of array a[ ] . Updation in array a[ ] will be done based on the input of ticket numbers (by referring the index of array a[ ] as ticket number a[ticket_number] + = 1 ).
Counting the teams :-Dividing the frequencies of all ticket numbers by 2 and adding them all will give us the total number of teams (A unique team consist of pair of two matching ticket numbers ).
SOLUTIONS:
Setter's Solution
/*
Author- Shubham Goswami
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--){
int N,i,pairs=0,temp;
cin>>N;
int a[100]={0};
for(i=0;i<N;i++){
cin>>temp;
a[temp]+=1;
}
for(i=0;i<100;i++){
pairs+=(a[i]/2);
}
cout<<pairs<<"\n";
}
return 0;
}