Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 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 LongestNonDecreasingSubsequence
  8. {
  9.     class LongestNonDecreasingSubsequence
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] sentence = Console.ReadLine().Split();
  14.             int[] array = new int[sentence.Length];
  15.             List<string> final = new List<string>();
  16.  
  17.             for (int i = 0; i < sentence.Length; i++)
  18.             {
  19.                 for (int h = 0; h < sentence.Length; h++)
  20.                 {
  21.                     List<string> temp = new List<string>();
  22.                     List<string> temp2 = new List<string>();
  23.                     temp.Add(sentence[h]);
  24.                     temp2.Add(sentence[h]);
  25.                     string letter = sentence[h];
  26.                     string letter2 = sentence[h];
  27.                     for (int j = h + 1; j < sentence.Length; j++)
  28.                     {
  29.                         if (sentence[i] == sentence[j])
  30.                         {
  31.                             continue;
  32.                         }
  33.                         else if (int.Parse(letter) < int.Parse(sentence[j].ToString()))
  34.                         {
  35.                             letter = sentence[j];
  36.                             temp.Add(sentence[j]);                            
  37.                         }
  38.                         else if (int.Parse(letter2) == int.Parse(sentence[j].ToString()))
  39.                         {
  40.                             letter2 = sentence[j];
  41.                             temp2.Add(sentence[j]);
  42.                         }
  43.                         else
  44.                         {
  45.                             continue;
  46.                         }
  47.                     }
  48.                     if (temp.Count > final.Count)
  49.                     {
  50.                         final = temp;
  51.                     }
  52.                     else if (temp2.Count > final.Count)
  53.                     {
  54.                         final = temp2;
  55.                     }
  56.                     else
  57.                     {
  58.                         continue;
  59.                     }
  60.                 }            
  61.             }
  62.             foreach (var item in final)
  63.             {
  64.                 Console.Write(item + " ");
  65.             }
  66.             //unfinished
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement