Question:Given two strings with the length of N, determine whether the 26 letters can match one by one. That is, after a one-to-one ing, the two strings are the same. Input two strings and output yes or no.
Ideas:You only need to determine whether the number of letters can be exactly one-to-one. For example, if S1 has three characters, it must also exist in S2.
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 105; char S1 [maxn], s2 [maxn]; int num1 [maxn], num2 [maxn], V1 [maxn], V2 [maxn]; int main () {While (gets (S1 )! = NULL) {gets (S2); int Len = strlen (S1), flag = 1; memset (num1, 0, sizeof (num1); memset (num2, 0, sizeof (num2); memset (V1, 0, sizeof (V1); memset (V2, 0, sizeof (V2); For (INT I = 0; I <Len; I ++) {num1 [S1 [I]-'a'] ++; num2 [S2 [I]-'a'] ++ ;} for (INT I = 0; I <26; I ++) {v1 [num1 [I] ++; V2 [num2 [I] ++ ;} for (INT I = 0; I <26; I ++) {If (V1 [I]! = V2 [I]) {flag = 0; break ;}} if (FLAG) printf ("Yes \ n"); else printf ("NO \ n ");} return 0 ;}