Go to: Remove duplicate string combinations

Source: Internet
Author: User

From: http://bbs.csdn.net/topics/310249367

Super stupid wolf

Question: There is a string array of <string> = "ABC", "BAC", "ACB"... 0.1 million elements, each with a length of 3 to 16 characters.
Only one combination is retained. That is to say, strings with the same content are deleted only for strings with different character combinations.
The result must be calculated within one second.

 

The following figure shows the input data:

Static void main (string [] ARGs)
{
// 0.1 million strings.
Int totalstr = 10*10000;
List <string> myarr = new list <string> ();
Int totallength = 0;
Char [] input = "a hundred feet high in a dangerous building on a hundred feet higher than a hundred feet from the Yellow River to the current in the white sky, so that the stars do not speak loudly and may be stunned". tochararray ();
Random Rand = new random ();
For (INT I = 0; I <totalstr; I ++) // 0.1 million data records
{
String tempstr = "";
Int templength = Rand. Next (3, 16); // 3 to 16 characters
For (Int J = 0; j <templength; j ++)
{
Tempstr + = input [Rand. Next (0, input. Length)]; // use a-Z for English Testing
}
Totallength + = templength;
Myarr. Add (tempstr );
}

// Test starts
Long begin = system. datetime. Now. ticks;
// Write the program code here. You can write functions or classes to call them here.
........
Long end = system. datetime. Now. ticks;
Console. writeline ("Total" + totalstr/10000 + "pieces of data, total length" + totallength + ", after completion, we need" + system. timespan. fromticks (end-begin ). milliseconds + "millisecond ");
Console. Readline ();
}

 

Go to: Remove duplicate string combinations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.