Advertisement
Guest User

02. Integer Insertion

a guest
Mar 13th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace simpleArrays
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] flist = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14. string check = Console.ReadLine();
  15. while (!check.Equals("end"))
  16. {
  17. int pos = int.Parse(check[0]+"");
  18. int num = int.Parse(check);
  19. flist = getNewArray(pos,num,flist);
  20.  
  21.  
  22. check = Console.ReadLine();
  23. }
  24.  
  25. Console.WriteLine(string.Join(" ",flist));
  26. }
  27.  
  28. private static int[] getNewArray(int pos, int num, int[] flist)
  29. {
  30. int[] a = new int[flist.Length+1];
  31. int index = 0;
  32. for (int i = 0; i < a.Length; i++)
  33. {
  34. if (i == pos)
  35. {
  36. a[pos] = num;
  37. a[i + 1] = flist[i];
  38. }
  39. else
  40. {
  41. a[i] = flist[index];
  42. index++;
  43. }
  44. }
  45. return a;
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement