Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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 ConsoleApp138
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] nums = Console.ReadLine()
  14. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToArray();
  17. if (nums.Length < 2)
  18. {
  19. Console.WriteLine(OneDigit(nums));
  20. }
  21. if (nums.Length % 2 == 0)
  22. {
  23.  
  24. Console.WriteLine(Even(nums));
  25. }
  26. }
  27. static int OneDigit(int[] nums)
  28. {
  29. int res = 0;
  30. foreach (var item in nums)
  31. {
  32. res = item;
  33. }
  34. return res;
  35. }
  36. static int[] Even(int[] nums)
  37. {
  38.  
  39. int quantity = nums.Length;
  40. int[] res = new int[quantity];
  41. for (int i = 0; i < nums.Length; i++)
  42. {
  43. if (i == nums.Length / 2 - 1)
  44. {
  45. res[i] = nums[i];
  46. res[i + 1] = nums[i + 1];
  47. }
  48. nums[i] = res[i];
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement