Friday, 14 October 2016

Sock Merchant Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
    int ar[102],n,cnt[102] = {0},pairs = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> ar[i];
        cnt[ar[i]]++;
    }
    for(int i = 0; i < 101; i++){
        if(cnt[i]!= 0)pairs+=cnt[i]/2;
    }
    cout << pairs << endl;
    return 0;
}

2 comments: