what is my mistake--voters

#include
using namespace std;

int id[10000000];

int main()
{
int n1,n2,n3,temp,max,count;
cin>>n1>>n2>>n3;
n1=n1+n2+n3;
for(int i=0;i<n1;++i)
{
cin>>temp;
id[temp]=id[temp]+1;
if(id[temp]==2)
{
++count;

    }
    if(temp>max)
    {
                         max=temp;
    }
}
cout<<count<<"\n";
for(int i=0;i<=max;++i)
{
          if(id[i]>=2)
          {
                    cout<<i<<"\n";
          }
 }
  return 0;

}

1 Like

Well, i see what you are trying to do but you are toying around with uninitialized values.

Lets see, you declared id[10000000] but didn’t initialize its elements with ‘0’ so they contain some unwanted value (!=0) so performing increment operation ‘id[temp]=id[temp]+1’ will not give desired result, same with the variable ‘max’, you didn’t initialize it to ‘0’

You can either use memset on ‘id[10000000]’ or use ‘map’

Cheers

1 Like

uninitialized arrays and variables are zero ryt?? what is memset and map??from wer can i learnt it??..

thanks…i got correct

1 Like

no, uninitialized variable are not zero they contain some value(!=0)(check it out yourself, declare a variable and print it, you will realize), you need to initialize it. memset is used to easily initialize an array, like to initialize ‘id’-> “memset(id,0,10000000)” or you can run a loop from 10000000 times and equate each element to ‘0’