Advertisement
Guest User

LongestSequence

a guest
Sep 17th, 2015
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 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 LongestIncreasingSequence
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> numbers = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
  14. List<int> output = new List<int>();
  15. List<int> sequence = new List<int>();
  16. int count = 0;
  17. int startSequence = 0;
  18. int maxCount = 0;
  19. int maxStartIndex = 0;
  20. for (int i = 0; i < numbers.Count() - 1; i++)
  21. {
  22. if (count == 0)
  23. startSequence = i;
  24. if (numbers[i] <numbers[i + 1])
  25. count++;
  26. else
  27. {
  28. for (int j = 0; j <= count; j++)
  29. {
  30. Console.Write("{0} ",numbers[startSequence+j]);
  31. }
  32. if (count > maxCount)
  33. {
  34. maxCount = count;
  35. maxStartIndex = startSequence;
  36. }
  37. count = 0;
  38. Console.WriteLine();
  39. if (i == numbers.Count() - 2)
  40. {
  41. Console.WriteLine(numbers[numbers.Count - 1]);
  42. }
  43. }
  44. }
  45. if(count!=0)
  46. {
  47. for (int j = 0; j <= count; j++)
  48. {
  49. Console.Write("{0} ", numbers[startSequence + j]);
  50. if (count > maxCount)
  51. {
  52. maxCount = count;
  53. maxStartIndex = startSequence;
  54. }
  55. }
  56. Console.WriteLine();
  57. }
  58. Console.Write("Longest: ");
  59. for (int m = 0; m <= maxCount; m++)
  60. {
  61. Console.Write("{0} ",numbers[maxStartIndex+m]);
  62. }
  63. Console.WriteLine();
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement