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.