Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. namespace Task_1
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. string numbersFromConsole = Console.ReadLine(); //1.read numbers from console
  12.  
  13. var arrayOfNumbers = numbersFromConsole // 2.split the numbers by space and parse them to array
  14. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToArray();
  17.  
  18. Array.Sort(arrayOfNumbers); //3. sorting the array
  19.  
  20. //TODO:
  21. // last answer!
  22. for (int i = 0; i < arrayOfNumbers.Length - 1; i++)
  23. {
  24. if (arrayOfNumbers[i + 1] - arrayOfNumbers[i] == 1)
  25. {
  26. continue;
  27. }
  28.  
  29. else
  30. {
  31. Console.WriteLine("Not consecutive numbers");
  32. return;
  33. }
  34.  
  35.  
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement