fork download
  1. #include <stdio.h>
  2.  
  3. int a[1000], temp[1000];
  4.  
  5. int main() {
  6. int n, m;
  7. scanf("%d %d", &n, &m);
  8.  
  9. for (int i = 0; i < n; i++) a[i] = i + 1;
  10.  
  11. for (int k = 0; k < m; k++) {
  12. int x;
  13. scanf("%d", &x);
  14. int idx;
  15. for (int i = 0; i < n; i++) {
  16. if (a[i] == x) {
  17. idx = i;
  18. break;
  19. }
  20. }
  21.  
  22. int pos = 0;
  23. for (int i = idx + 1; i < n; i++) temp[pos++] = a[i];
  24. temp[pos++] = x;
  25. for (int i = 0; i < idx; i++) temp[pos++] = a[i];
  26.  
  27. for (int i = 0; i < n; i++) a[i] = temp[i];
  28. }
  29.  
  30. for (int i = 0; i < n; i++) printf("%d\n", a[i]);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5320KB
stdin
10 6 5 4 2 5 9 10
stdout
9
1
5
3
2
4
6
7
8
10