`
kmplayer
  • 浏览: 497681 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

"abc","acb"相等

 
阅读更多
问题:字符串的字符各不相同,字符种类相等就是相等
1,bitvector,弄个简单的hash映射即可.
2,实例代码:
#include <iostream>
using namespace std;

int hash(const char* a)
{

    int tmp=0;
    while(*a)
    {
        tmp|=1<<(*a-'a');
        a++;
    }
    return tmp;
}

int main()
{
    char* a="abc";
    char* b="acb";
    cout<<hash(a)<<endl;
    cout<<hash(b)<<endl;
	return 0;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics