String Transformation——AT

题目描述

You are given strings S and T consisting of lowercase English letters.
You can perform the following operation on S any number of times:
Operation: Choose two distinct lowercase English letters c1 and c2, then replace every occurrence of c1 with c2, and every occurrence of c2 with c1.
Determine if S and T can be made equal by performing the operation zero or more times.

Constraints
·1≤|S|≤2×105
·|S|=|T|
·S and T consists of lowercase English letters.

输入

Input is given from Standard Input in the following format:
S T

输出

If S and T can be made equal, print Yes; otherwise, print No.

样例输入

azzel
apple

样例输出

yes

提示

azzel can be changed to apple, as follows:
·Choose e as c1 and l as c2. azzel becomes azzle.
·Choose z as c1 and p as c2. azzle becomes apple.

#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
string ss1,ss2;
vector<char> str1(26, ' ');
vector<char> str2(26, ' ');
start{
    cin >>ss1>>ss2;
    int flag=1;
    for (int i=0;i<ss1.size();i++){
        if(str1[ss1[i]-97]==' ')
            str1[ss1[i]-97]=ss2[i];
        else if(str1[ss1[i]-97]!=ss2[i])
            flag=0;
        if(str2[ss2[i]-97]==' ')
            str2[ss2[i]-97]=ss1[i];
        else if(str2[ss2[i]-97]!=ss1[i])
            flag=0;
    }
    if(flag) printf("Yes
");
    else
        printf("No
");
    end;
}
 
/**************************************************************
    Language: C++
    Result: 正确
    Time:27 ms
    Memory:2824 kb
****************************************************************/
原文地址:https://www.cnblogs.com/PushyTao/p/13144184.html