兄弟字串(轉)

來源:互聯網
上載者:User

標籤:

 1 /*  2 如果兩個字串的字元一樣,但是順序不一樣,被認為是兄弟字串,  3 問如何在迅速匹配兄弟字串(如,bad和adb就是兄弟字串)。  4 */   5 #include <iostream>   6 using namespace std;   7    8 int isBroStr(char *str1, char *str2)   9 {  10     int a[60] = {0};  11     int i, strLen;  12       13     if (!str1 && !str2)  14         return 1;  15     else if (!str1 || !str2)  16         return 0;  17     else  18     {  19         if(strlen(str1) != strlen(str2))  20             return 0;  21         strLen = strlen(str1);  22         for(i = 0; i < strLen; i++)  23         {  24             ++a[str1[i] - ‘A‘];  25             --a[str2[i] - ‘A‘];  26         }  27         for(i = 0; i <60; i++)  28             if (a[i])  29                 return 0;  30         return 1;  31     }          32 }  33   34 int main()  35 {  36     char *str1 = "asdfaabAAB";  37     char *str2 = "asdfAABaab";  38     if (isBroStr(str1, str2))  39         cout << " String 1 and String 2 are brothers!" << endl;  40     else  41         cout << " String 1 and String 2 are not brothers!" << endl;  42     system("PAUSE");  43     return 0;  44 }  

 

兄弟字串(轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.