Advertisement
RoshHoul

Untitled

Sep 26th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1.        static void Main(string[] args)
  2.         {
  3.             List<string> words = new List<string>();
  4.             List<string> results = new List<string>();
  5.             var n = Int32.Parse(Console.ReadLine());
  6.             char charChain = 'a';
  7.  
  8.             for (int i = 0; i < n; i++)
  9.             {
  10.                 var word = Console.ReadLine().ToLower();
  11.                 words.Add(word);
  12.             }
  13.  
  14.             string last = words.Last();
  15.             foreach (string s in words)
  16.             {
  17.                 var word = s.ToArray();
  18.                 List<string> iterationList = new List<string>();
  19.                 iterationList.Add(s);
  20.                 char chainLink = word[word.Length - 1];
  21.                
  22.                 Console.WriteLine("in the chain of " + s + ": ");
  23.                 foreach (string s1 in words)
  24.                 {
  25.                     Console.WriteLine("Chainlink is " + chainLink + " in beginning and word is " + s1);
  26.                     var word1 = s1.ToArray();
  27.                     if (chainLink == word1[0] && !iterationList.Contains(s1) )
  28.                     {
  29.                         iterationList.Add(s1);
  30.                         chainLink = word1[word1.Length - 1];
  31.                         Console.WriteLine(s1 + " added and chainlink is " + chainLink);
  32.                      
  33.                     }    
  34.                 }
  35.  
  36.                 //foreach (string blabla in iterationList)
  37.                 //{
  38.                 //    Console.WriteLine("The list of " + iterationList[0] + " is: " + blabla);
  39.                 //}
  40.                
  41.                 if ( iterationList.Count() > results.Count() )
  42.                 {
  43.                     results = iterationList;
  44.                 }
  45.             }
  46.             //results = results.Distinct().ToList();
  47.             if (results.Count() > 1)
  48.             {
  49.                 Console.WriteLine(results.Count());
  50.                 foreach (string result in results)
  51.                 {
  52.                     Console.WriteLine(result);
  53.                 }
  54.             } else
  55.             {
  56.                 Console.WriteLine(0);
  57.             }
  58.             Console.ReadKey();
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement