Thinking path: Use the character as the subscript of the array (the C language allows ing the character into an integer to act as the subscript of the array) or as the key word of the hash table.
Viod removechars (char STR [], char remove [])
Note: All characters in remove must be removed from Str.
For example, if STR: "Battle of the vowels: Hawaii vs. Grozny ",
Remove: "aeiou ",
Result: STR is converted to "bttl F th vwls: HW vs. grzny ".
# Include <iostream>
# Include <string. h>
Using namespace STD;
Void removechars (char STR [], char remove []);
Void main ()
{
Char STR [50], remove [10];
Cout <"Enter the main string :";
Cin. Getline (STR, 50 );
Cout <"Enter the character set to be deleted :";
Cin> remove;
Cout <"output STR after deleting a specific character set :";
Removechars (STR, remove );
Cout <STR <Endl;
}
Void removechars (char STR [], char remove [])
{
Int SRC, DST, removearray [1, 256];
For (src = 0; SRC <256; SRC ++)
{
Removearray [SRC] = 0;
}
Src = 0;
While (remove [SRC])
{
Removearray [remove [SRC] = 1;
SRC ++;
}
Src = DST = 0;
Do
{
If (! Removearray [STR [SRC])
STR [DST ++] = STR [SRC];
} While (STR [SRC ++]);
}
(2)
# Include <iostream>
# Include <vector>
Using namespace STD;
Bool find (char C, STD: vector <char> & substr)
{
STD: vector <char >:: iterator ITER;
For (iter = substr. Begin (); iter! = Substr. End (); ++ ITER)
If (* iter = C)
Return true;
Return false;
}
Void strdeal (char * STR, char * substr)
{
Char strtemp [1000];
STD: vector <char> substr;
Int J = 0;
While (substr [J])
{
Substr. push_back (substr [J]);
J ++;
}
J = 0;
Int I = 0;
While (STR [J])
{
If (! Find (STR [J], substr ))
Strtemp [I ++] = STR [J];
J ++;
}
Strtemp [I] = '/0 ';
Cout <strtemp <Endl;
}
Int main ()
{
Char STR [1000];
Cin. Getline (STR, 1000 );
Strdeal (STR, "aeiou ");
Return 0;
}