fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. unordered_set <int> s;
  4. int a[10]={3, 5, 7, 3, 3, 13, 5, 13, 29, 13};
  5. void shift(int i){
  6. do{
  7.  
  8. a[i]=a[i+1];
  9. i++;
  10.  
  11. }while(i!=10);
  12. }
  13. int main(){
  14. int tot=0;
  15. for(int i=0;i<10-tot;i++){
  16. if(s.find(a[i])!=s.end()){
  17. tot++;
  18. shift(i);
  19. i--;
  20.  
  21. }
  22. else{
  23. s.insert(a[i]);
  24. }
  25. }
  26.  
  27. //printing
  28. for(int j=0;j<10-tot;j++){
  29. printf("%d ",a[j]);
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
3 5 7 13 29