转:去掉重复的字符串组合

转自:http://bbs.csdn.net/topics/310249367

超级大笨狼

题目:有一个字符串数组 List<string>="abc","bac","acb".....10万个元素,每个长度在3到16个字符。
只保留其中一个组合,也就是说对于字符串内容相同,只是字符组合顺序不同的字符串进行删除。
要求结果在一秒内算出。

下面是输入的数据:

        static void Main(string[] args) 
        {              
            //10万个字符串。 
            int totalStr = 10*10000; 
            List <string> myArr = new List <string>(); 
            int totalLength = 0; 
            char[] input = "白日依山尽黄河入海流欲穷千里目更上一层楼危楼高百尺可以摘星辰不感高声语恐惊天上人".ToCharArray(); 
            Random rand = new Random(); 
            for (int i = 0; i < totalStr; i++)//10万个数据 
            { 
                string tempStr = ""; 
                int tempLength = rand.Next(3, 16); //3到16个字符                
                for (int j = 0; j < tempLength; j++) 
                { 
                    tempStr += input[rand.Next(0, input.Length)];//用a-z英文测试 
                } 
                totalLength += tempLength; 
                myArr.Add(tempStr); 
            } 

            //测试开始 
            long begin = System.DateTime.Now.Ticks;          
            //这里写程序代码,可以写函数或类什么的在此调用。
   。。。。。。。。
            long end = System.DateTime.Now.Ticks; 
            Console.WriteLine("总共" + totalStr/10000 + "万个数据,总长度" + totalLength + ",做完需要" + System.TimeSpan.FromTicks(end - begin).Milliseconds + "毫秒"); 
            Console.ReadLine(); 
}

原文地址:https://www.cnblogs.com/kira2will/p/4014911.html