Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- List<string> words = new List<string>();
- List<string> results = new List<string>();
- var n = Int32.Parse(Console.ReadLine());
- char charChain = 'a';
- for (int i = 0; i < n; i++)
- {
- var word = Console.ReadLine().ToLower();
- words.Add(word);
- }
- string last = words.Last();
- foreach (string s in words)
- {
- var word = s.ToArray();
- List<string> iterationList = new List<string>();
- iterationList.Add(s);
- char chainLink = word[word.Length - 1];
- Console.WriteLine("in the chain of " + s + ": ");
- foreach (string s1 in words)
- {
- Console.WriteLine("Chainlink is " + chainLink + " in beginning and word is " + s1);
- var word1 = s1.ToArray();
- if (chainLink == word1[0] && !iterationList.Contains(s1) )
- {
- iterationList.Add(s1);
- chainLink = word1[word1.Length - 1];
- Console.WriteLine(s1 + " added and chainlink is " + chainLink);
- }
- }
- //foreach (string blabla in iterationList)
- //{
- // Console.WriteLine("The list of " + iterationList[0] + " is: " + blabla);
- //}
- if ( iterationList.Count() > results.Count() )
- {
- results = iterationList;
- }
- }
- //results = results.Distinct().ToList();
- if (results.Count() > 1)
- {
- Console.WriteLine(results.Count());
- foreach (string result in results)
- {
- Console.WriteLine(result);
- }
- } else
- {
- Console.WriteLine(0);
- }
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement