Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace NameAnalyser
- {
- class Program
- {
- static void Main()
- {
- Analyser a = new Analyser(@"C:\Users\Ali\Desktop\names.txt");
- a.FindTuples();
- int maxSize = a.Tuples.Max(x => x.Count);
- int numberOfMax = a.Tuples.Where(x => x.Count == maxSize).ToArray<List<string>>().Length;
- Console.WriteLine(maxSize * numberOfMax);
- Console.ReadLine();
- }
- }
- class Analyser
- {
- private List<string> names;
- public List<string> Names
- {
- get
- {
- return names;
- }
- }
- private List<List<string>> tuples;
- public List<List<string>> Tuples
- {
- get
- {
- return tuples;
- }
- }
- public Analyser(string path)
- {
- names = System.IO.File.ReadAllText(path).Split(new string[1] { "\",\"" }, StringSplitOptions.None).ToList<string>();
- names[0] = names[0].Trim('"');
- names [names.Count - 1] = names[names.Count - 1].Trim('"');
- }
- public bool AreAnagrams(string first, string second)
- {
- var firstList = first.ToList<char>();
- var secondList = second.ToList<char>();
- while (firstList.Count > 0)
- {
- if (secondList.Contains(firstList[0]))
- {
- secondList.Remove(firstList[0]);
- firstList.Remove(firstList[0]);
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- public void FindTuples()
- {
- tuples = new List<List<string>>();
- for (int i = 0; i < names.Count; i++)
- {
- List<string> tuple = new List<string>();
- string name = names[0];
- names.RemoveAt(0);
- tuple.Add(name);
- for (int j = 0; j < names.Count; j++)
- {
- if (name.Length == names[j].Length && AreAnagrams(names[j], name))
- {
- tuple.Add(names[j]);
- names.RemoveAt(j);
- j--;
- }
- }
- tuples.Add(tuple);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement