Advertisement
compiler13

Inventory

Oct 4th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define mx 100005
  3.  
  4. using namespace std;
  5. int main()
  6. {
  7.     long ar[mx]= {0};
  8.     long ar1[mx]= {0};
  9.     long long n,i,a,j,ar2[mx],k;
  10.  
  11.     cin>>n;
  12.  
  13.     for(i=1; i<=n; i++)
  14.     {
  15.  
  16.         cin>>a;
  17.  
  18.         if(a<=n)
  19.         {
  20.             ar[i]=a;
  21.             ar1[a]=1;
  22.         }
  23.  
  24.  
  25.  
  26.     }
  27.     k=1;
  28.  
  29.     for(i=1; i<=n; i++)
  30.     {
  31.         if(ar1[i]!=1)
  32.         {
  33.             ar2[k++]=i;
  34.         }
  35.     }
  36.     k=1;
  37.  
  38.  
  39.     for(i=1; i<n; i++)
  40.     {
  41.         for(j=i+1; j<=n; j++)
  42.         {
  43.  
  44.             if(ar[i]==ar[j])
  45.             {
  46.                 ar[j]=ar2[k++];
  47.             }
  48.         }
  49.  
  50.     }
  51.     for(i=1; i<=n; i++)
  52.     {
  53.         cout<<ar[i]<<" ";
  54.     }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement