fork(1) download
  1. #include<stdio.h>
  2. int main(){
  3. int a[1000];
  4. int b[1000];
  5. int k=1;
  6. int n,m;
  7. int p,count=0;
  8. int x=0;
  9. int key;
  10. scanf("%d",&n);
  11. scanf("%d",&m);
  12. for(int z=0;z<=1000;z++){
  13. a[z]=0;
  14. b[z]=0;
  15. }
  16. for(int i=0;i<n;i++){
  17. a[i]=k;
  18. k++;
  19. }
  20.  
  21. for(int q=0;q<m;q++){
  22. scanf("%d",&p);
  23. for(int j=0;j<n;j++){
  24. if(a[j]==p){
  25. key=j;
  26. }
  27. }
  28. count=key+1;
  29. while(count<n){
  30. b[x]=a[count];
  31. count++;
  32. x++;
  33. }
  34. b[x]=p;
  35. x++;
  36. count=0;
  37. while(count<q){
  38. b[x]=a[count];
  39. count++;
  40. x++;
  41. }
  42. x=0;
  43. for(int r=0;r<n;r++){
  44. printf("%d ",b[r]);
  45. }
  46. }
  47. }
  48.  
  49.  
  50.  
Success #stdin #stdout 0.01s 5320KB
stdin
8 4
4 5 6 6
stdout
5 6 7 8 4 0 0 0 6 7 8 5 1 0 0 0 7 8 6 1 2 0 0 0 7 8 6 1 2 3 0 0