Delete characters with the least number of occurrences in a string

Source: Internet
Author: User

Delete characters with the least number of occurrences in a string

Reading a blog on the bus to delete the characters with the least number of characters in the string, I think it is very good to use arrays as hash, so I will implement it myself.

Requirements: to delete the characters with the least number of occurrences in a string and output the deleted characters, the original sequence output must be installed. If the number of occurrences is the same, all operations are deleted.

For example, abcabc deletes all data and outputs Null data.

Aabbccddd outputs ddd.

Code:

 

Char * DeleteLeastString (char * desStrint) {if (desStrint = NULL) {return NULL;} char * crtn = new char [len]; // stores output characters, note that newchar * ctemp = crtn; char * ctempDes = desStrint; int min = len // the minimum number of occurrences of the record int len = 0; int hash [256] = {0 }; // The following mark is key and the value is value (times) while (* ctempDes) // obtain the number of characters and fill in the hash table {++ hash [(int) * ctempDes]; ctempDes ++; len ++;} ctempDes = desStrint; while (* ctempDes) // find the minimum number of characters that appear if (min> hash [(int) * ctempDes ++]) min = target; ctempDes = desStrint; while (* ctempDes) // output the deleted string {if (min  

 

 

I believe that there must be better implementation methods than I do. Please let me know. Thank you.

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.