Several problems in string processing

Source: Internet
Author: User

1. For two strings A and B, if A and b appear in the same type of characters and each character appears the same number of times, then A and B are deformed words, design an efficient algorithm to check whether two given strings are mutually deformable words.

Given the two strings a and B and their lengths, return a bool value that indicates whether they are mutually deformed words.

Test examples:
"ABC", 3, "BCA", 3
Return: True
/* Use the array to simulate the hash table, each character corresponding to the ASCII code as an array subscript every time the corresponding character appears to initialize the array to 0 to assign a value of 1, so that the other string only need to find in this array, if each character corresponding to the array element is 1, then Illustrates that two strings are deformed words, not */class Transform {public:    bool Chktransform (string A, int lena, string B, int lenb) {        //write C Ode here       if (LENA!=LENB)//length is not equal to direct return false return False           ;        const char *PA=A.C_STR ();//convert string to const char*        const char *pb=b.c_str ();        int arr[256]={0};        while (*PA) {            arr[*pa]=1;            pa++;        }        while (*PB) {            if (arr[*pb]!=1)                return false;            pb++;        }        return true;    }};

  

Several problems in string processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.