示例#1
0
 public void Output(List <String> list)
 {
     using (StreamWriter sw = File.CreateText(outFileName)) {
         HashSet <String> set = new HashSet <String>();
         for (Int32 i = 0, j = 0; i < list.Count;)
         {
             String anagramGroup = WordAnagramComparer.GetAnagramString(list[i]);
             for (j = 0; i + j <= list.Count; j++)
             {
                 if (i + j == list.Count)
                 {
                     PrintLineFromSet(set, sw);
                     return;
                 }
                 if (AreWordsFromSameAnagramGroup(list[i], list[i + j]))
                 {
                     set.Add(list[i + j]);
                 }
                 else
                 {
                     i = i + j;
                     PrintLineFromSet(set, sw);
                     break;
                 }
             }
         }
     }
 }
示例#2
0
 private static Boolean AreWordsFromSameAnagramGroup(String word1, String word2)
 {
     return(WordAnagramComparer.GetAnagramString(word1) == WordAnagramComparer.GetAnagramString(word2));
 }