C++ハッシュテーブルによる文字列の処理


関数を定義し、2つの文字列を入力し、1番目の文字列から2番目の文字列の重複文字を削除します.
#include 
#include 
using namespace std;
string delete_duplicate_char(string str,const string str1) {
    if(str1.empty())
        return str;
    map table;
    for(auto temp:str1)
        table[temp]++;

    string output;
    for(auto temp:str){
        if(table[temp]==1)
            continue;
        output+=temp;		
    }
    return output;
}
int main()
{
   cout<

関数を定義して文字列内のすべての重複する文字を削除します.
#include 
#include 
#include 
using namespace std;

string delete_repeating_char(string str){
	if(str.empty())
		return "";
	set table;        //    char string      
	string output;
	for(auto temp:str){
		auto value = table.insert(temp);  //insert     pair  first           ,second bool ,       true,                false
    //pair::iterator,bool> value = table.insert(temp);
		if(value.second)
			output+=temp;
	}
	return output;
}
int main()
{
	string a;
	cout<< delete_repeating_char(a)<

英語では、liveなどの2つの単語が対称であれば、evilは互いに変位語と呼ばれます.
#include 
#include 
#include 

using namespace std;

bool decide_anagram(string str,string str1){
	if(str.empty() || str1.empty())
		return false;
	map table;
	string output;
	for(auto temp:str)
		table[temp]++;
	for(auto temp:str1)
		table[temp]--;
	for(auto it=table.begin();it!=table.end();it++){
		if(it->second !=0)
			return false;
	}
	return true;
}
int main()
{
	string a,b;
	cout<< decide_anagram(a,b)<