Advertisement
montimaj

SINGLETON

Mar 29th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. // Every element in an array is repeated twice except one. Find that element.
  2.  
  3. #include<iostream>
  4. int main()
  5. {
  6.     int n;
  7.     std::cout<<"Enter vector size: ";
  8.     std::cin>>n;
  9.     int *a=new int[n];
  10.     for(int i=0;i<n;++i)
  11.     {
  12.         std::cout<<"\nNum "<<i<<"= ";
  13.         std::cin>>a[i];
  14.     }
  15.     for(int i=0;i<n;++i)
  16.         a[i+1]^=a[i];
  17.     std::cout<<"\nSingleton element= "<<a[n-1];
  18.     delete[] a;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement