fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, v[100];
  6. cin >> n;
  7. for (int i = 1; i <= n; ++i) { // Citim sirul
  8. cin >> v[i];
  9. }
  10. int x, p; // Numarul si pozitia pe care sa fie inserat
  11. cin >> x >> p;
  12. ++n; // Crestem lungimea sirului
  13. for (int i = n; i > p; --i) { // Mutam elementele cu o pozitie la dreapta
  14. v[i] = v[i - 1];
  15. }
  16. v[p] = x;
  17. for (int i = 1; i <= n; ++i) { // Afisam sirul
  18. cout << v[i] << ' ';
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 5324KB
stdin
4
1 2 3 4
7 3
stdout
1 2 7 3 4