fork download
  1. #include<conio.h>
  2. #include<stdio.h>
  3. #include<iostream.h>
  4. int main()
  5. {
  6. int i;
  7. //int a[] = {1,5,5,2,3,4,2,3,4,5};
  8. int a[]={3,1,5,2,2,3,5,3,4,4};
  9. int n = sizeof(a)/sizeof(a[0]);
  10. int xor_val = a[0];
  11. for(i=1;i<n;i++)
  12. xor_val^=a[i];//Find xor sum of all the values
  13. int count = 0; //To find the rightmost i-th bit set in xor_val
  14. int x = 0;int y = 0;
  15. int xfreq = 0,yfreq = 0; //to store respective frequencies of x and y
  16. //Find the i-th 1 bit (rightmost)
  17. while((xor_val & (1<<count))==0)
  18. count++;
  19.  
  20. //Find the element with i-th bit = 0
  21.  
  22. for(i=0;i<n;i++)
  23. {
  24. if((a[i] & (1<< count)) == 0)//that is if the count-th bit is zero
  25. x^= a[i]; //find the xor sum of those values
  26.  
  27. }
  28. //Find the element were i-th bit is set
  29. for(i=0;i<n;i++)
  30. {
  31. if((a[i] & (1<<count)) != 0) //xor sum of the numbers whose i-th (= count ) bit is not set
  32. y^=a[i];
  33. }
  34. //Now either of x or y is the desired number
  35. for(i=0;i<n;i++)
  36. {
  37. if(a[i]==x)
  38. xfreq++;
  39. else if(a[i]==y)
  40. yfreq++;
  41. }
  42. xfreq > yfreq ? (cout<<"\nThe number which repeats thrice = "<<x) :(cout<<"\nThe number which repeats thrice = "<<y);
  43.  
  44. getch();
  45. return 0;
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:18: error: conio.h: No such file or directory
prog.cpp:3:21: error: iostream.h: No such file or directory
prog.cpp: In function ‘int main()’:
prog.cpp:42: error: ‘cout’ was not declared in this scope
prog.cpp:44: error: ‘getch’ was not declared in this scope
stdout
Standard output is empty