fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int n ; cin>>n;
  9. int count=0;
  10. vector<int>arr(n);
  11. for(int i =0;i<n;i++){
  12. cin>>arr[i];
  13. }
  14. vector<bool>vis(n,false);
  15. for(int i =0;i<n;i++){
  16. if(!vis[i]){
  17. count++;
  18. for(int j =0;j<n;j++){
  19. if (arr[i]==arr[j]){
  20. vis[j]=true;
  21. }
  22. }
  23.  
  24. }
  25.  
  26. }
  27. cout<<"total number of unique elements "<<count<<endl;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5328KB
stdin
7

1 2 2 5 6 6 7 
stdout
total number of unique elements 5