Sunday, November 12, 2017

DCP-272: Find the Intersection Devskilll Problem Solution

https://www.devskill.com/CodingProblems/ViewProblem/272


#include<bits/stdc++.h>

using namespace std;

int a[1001];

int main()

{
    int f;
    cin>>f;
    while(f--){
    memset(a,0,sizeof(a));
    int n;
    cin>>n;
    cin.ignore();
    string s;
    for(int i=0;i<n;i++){
    int number=0;
    getline(cin,s);
    for(int j=0;j<s.size();j++)
    {
        if(s[j]==' ')
        {
            a[number]++;
            number=0;
        }
        else
        {
            number=number*10+((s[j]-'0'));
        }
    }
    a[number]++;

    }
     int firsttime=0;
    for(int w=0;w<1001;w++)
    {
        if(a[w]==n&&firsttime==0)
        {
            cout<<w;
            firsttime=1;
        }
        else if(a[w]==n &&firsttime==1)
        {
            cout<<" "<<w;
        }
    }
    if(firsttime==0)
    {
        cout<<"Empty";
    }
    cout<<endl;
    }
    return 0;
}

No comments:

Post a Comment