Advertisement
tandaleyo

Problem 8.* Longest Non-Decreasing Subsequence

Dec 12th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 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 P08LongestNonDecreasingSubsequence
  8. {
  9. class P08LongestNonDecreasingSubsequence
  10. {
  11.  
  12. static void Main()
  13. {
  14. string input = Console.ReadLine();
  15. string[] list = input.Split(' ');
  16. int[] numbers = new int[list.Length];
  17.  
  18. for (int i = 0; i < list.Length; i++)
  19. {
  20. numbers[i] = int.Parse(list[i]);
  21. }
  22.  
  23.  
  24. List<int> tempList = new List<int>();
  25. List<int> printList = new List<int>();
  26.  
  27. for (int i = 0; i < numbers.Length; i++)
  28. {
  29. for (int j = i; j < numbers.Length; j++)
  30. {
  31. if (j == 0)
  32. {
  33. tempList.Add(numbers[j]);
  34. continue;
  35. }
  36.  
  37. if (numbers[j] > tempList.Last())
  38. {
  39. tempList.Add(numbers[j]);
  40. }
  41. }
  42.  
  43. if (tempList.Count > printList.Count)
  44. {
  45. printList = tempList;
  46. tempList.Clear();
  47. }
  48. }
  49.  
  50. foreach (var item in printList)
  51. {
  52. Console.WriteLine(item);
  53. }
  54.  
  55.  
  56.  
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement