Removes all characters from the first string that appear in the second string
"We are students" "Aeiou" "W R studnts"
#include <stdio.h>#include <string>#include <memory>#include <iostream>using namespace STD;voiddel_chrs (Char*SRC,Char*del_chs) {if(src = = NULL | | del_chs==null)return;//Create and initialize a hash table Const intHashlength = the;unsigned intHashtable[hashlength]; for(inti =0; i < hashlength; i++) {Hashtable[i] =0; }the number of occurrences of each character in the second string stored in the//hash table Char*pdelch = Del_chs; while(*pdelch! =' + ') {Hashtable[*pdelch] =1; pdelch++; }//If the character pointed to by Pfast does not need to be deleted, assign the value it refers to Pslow, both of which move backwards//Otherwise, the pfast moves back and continues to look for, pslow not move. Char*p_slow = src;Char*p_fast = src;/* while (*p_fast! = ') {if (hashtable[*p_fast] = = 0) {*p_slow = *p_fast; p_slow++; } p_fast++; }*/ while(*p_fast) {if(Hashtable[*p_fast] = =1) {p_fast++; } *p_slow++ = *p_fast++; } *p_slow =' + ';}intMain () {/*const int strmaxlength = 100; Char strfirst [strmaxlength]; Cin.getline (strfirst,sizeof (Strfirst)); Char Strsecond[strmaxlength]; Cin.getline (strsecond,sizeof (Strsecond)); */ CharStrfirst[] ="They is students";CharStrsecond[] ="Aeiou"; del_chrs (Strfirst,strsecond);cout<< Strfirst <<endl;return 0;}
- Defines a function that deletes all occurrences of a character in a string.
"Google" "Gole"
#include <iostream>#include <string.h>using namespace STD;voidStringfilterfast (Const Char*PINPUTSTR) {Char*poutputstr=New Char[strlen(PINPUTSTR) +1];CharRstchar =' + ';BOOLBnotrepeatfound =false;Const unsigned intSize = the;unsigned intHashtable[size];Const Char* Phashkey = PINPUTSTR;intoutputcnt =0;if(pinputstr== NULL) {return; }//Initialize hash table for(unsigned inti =0; i < size; i++) {hashtable[i]=0; }//pstring read into the hash table while(*phashkey!=' + ') {cout<< *phashkey <<"\ T"; hashtable[*phashkey]++;//Statistics Countphashkey++; }//Read hash table, for only 1 occurrences of storage, the occurrence of more than 1 times the storage. Phashkey= Pinputstr; while(*phashkey!=' + ') {if((hashtable[* (phashkey)) = =1)//Only once,{poutputstr[outputcnt++]= *phashkey; }Else if((hashtable[* (Phashkey)) >1)//extra time, statistics for the first time{poutputstr[outputcnt++]= *phashkey; hashtable[* (Phashkey)]=0; } phashkey++; } poutputstr[outputcnt]=' + ';cout<< Poutputstr;}intMain () {Const Char* STRSRC ="Google";//"DESDEFEDEFFDSSW"; //char*strrst =new Char[strlen (STRSRC) +1];Stringfilterfast (STRSRC);//cout<< strrst << Endl; //if (NULL! = Strrst) {delete[] strrst; Strrst = NULL;} return 0;}
http://blog.csdn.net/laoyang360/article/details/8026579
3. If the letters in the two words are the same, and each letter appears in the same number of occurrences, then the two words are each other (anagram). For example: Silent Listen/evil live.
Complete a function to determine if the input string is an inflection word.
#include <iostream>using namespace STD;#define No_of_charsBOOLAreanagram (Const Char*STR1,Const Char*STR2) {if(str1 = = NULL | | str2 = = NULL) {return false; }intCount[no_of_chars] = {0};intI for(i =0; Str1[i] && str2[i]; i++) {count[str1[i]]++; count[str2[i]]--; }if(Str1[i]! =' + '|| Str2[i]! =' + ') {return false; } for(i =0; i < No_of_chars; i++) {if(Count[i]! =0) {return false; } }return true;}intMainintargcChar* argv[]) {CharStr1[] ="Geeksforgeeks";CharStr2[] ="Forgeeksgeeks";if(Areanagram (STR1, str2)) {cout<<"The strings is anagram of each other"<< Endl; }Else{cout<<"The strings is not anagram of each of the"<< Endl; }return 0;}
Http://www.code123.cc/742.html
http://blog.csdn.net/lalor/article/details/7539717
String hash table