Advertisement
viraco4a

Untitled

Dec 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace task_4
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] arr1 = Console.ReadLine()
  14. .Split()
  15. .Select(s => int.Parse(s))
  16. .ToArray();
  17. int[] arr2 = Console.ReadLine()
  18. .Split()
  19. .Select(s => int.Parse(s))
  20. .ToArray();
  21. int n1 = arr1.Length;
  22. int n2 = arr2.Length;
  23. int n = Math.Max(n1, n2);
  24. int[] sum = new int[n];
  25. int[] local = new int[n];
  26. if (n1 == n2)
  27. {
  28. for (int i = 0; i < n; i++)
  29. {
  30. sum[i] = arr1[i] + arr2[i];
  31. }
  32. string result = string.Join(" ", sum);
  33. Console.WriteLine(result);
  34. }
  35. else if (n1 < n2)
  36. {
  37. int i, j = 0;
  38. for (i = 0; j <= n1; j++, i++)
  39. {
  40. if (i == n)
  41. {
  42. break;
  43. }
  44. if (j == n1)
  45. {
  46. j = 0;
  47. }
  48. local[i] = arr1[j];
  49. sum[i] = local[i] + arr2[i];
  50. }
  51. string result = string.Join(" ", sum);
  52. Console.WriteLine(result);
  53. }
  54. else if (n1 > n2)
  55. {
  56. int i, j = 0;
  57. for (i = 0; j <= n2; j++, i++)
  58. {
  59. if (i == n)
  60. {
  61. break;
  62. }
  63. if (j == n2)
  64. {
  65. j = 0;
  66. }
  67. local[i] = arr2[j];
  68. sum[i] = local[i] + arr1[i];
  69. }
  70. string result = string.Join(" ", sum);
  71. Console.WriteLine(result);
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement