C++ Solution: ACM ICPC Team Hackerrank

 ACM ICPC Team


Code:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,i,m,j,k,max=0,count=0,ways=0;
    cin>>n>>m;                                         // taking input number of attendee and topics

    string a[n];
    for(i=0;i<n;i++)                                     // taking input binary string 
    {
        cin>>a[i];
    }

    for(i=0;i<n-1;i++)                     // this loop will act for a pointer for first team mate
    {
        for(j=i+1;j<n;j++)                         // this loop will act for a pointer for second team mate
        {
            count=0;                             // counter to count no of subject known by each team

            for(k=0;k<m;k++)           // if any team member knows the subject the counter increases
            {
                if(a[i][k]=='1' || a[j][k]=='1')
                {
                    count++;
                }
            }
       
            if(max<count) // if the count is greater then the max value and no of team knowing max subject is reset
            {
                max=count;
                ways=0;
            }

            if(max==count) // if count is equal to max value then the team no of team knowing max subject is increased by 1 
            {
                ways++;
            }
        }
    }

    cout<<max<<endl<<ways<<endl;

    
    return 0;
}


ACM ICPC Team Hackerrank Solution in C++.

You can post your own solutions in any language in comments section we will review and post with your credits.

Post a Comment

0 Comments