寻找兄弟字符串

/* 
如果两个字符串的字符一样,但是顺序不一样,被认为是兄弟字符串, 
问如何在迅速匹配兄弟字符串(如,bad和adb就是兄弟字符串)。 
*/  
#include <iostream>  
#include<cstring>
using namespace std;  
  
int isBroStr(char *str1, char *str2)  
{  
    int a[26 * 2] = {0};  
    int i, strLen;  
      
    if (!str1 && !str2)  
        return 1;  
    else if (!str1 || !str2)  
        return 0;  
    else  
    {  
        if(strlen(str1) != strlen(str2))  
            return 0;  
        strLen = strlen(str1);  
        for(i = 0; i < strLen; i++)  
        {  
            ++a[str1[i] - 'A'];  
            --a[str2[i] - 'A'];  
        }  
        for(i = 0; i < 26 * 2; i++)  
            if (a[i])  
                return 0;  
        return 1;  
    }          
}  
  
int main()  
{  
    char *str1 = "asdfaabAAB";  
    char *str2 = "asdfAABaab";  
    if (isBroStr(str1, str2))  
        cout << " String 1 and String 2 are brothers!" << endl;  
    else  
        cout << " String 1 and String 2 are not brothers!" << endl;  
    system("PAUSE");  
    return 0;  
}  
原文地址:https://www.cnblogs.com/wft1990/p/6859837.html