ABC110 C - String Transformation

 

C - String Transformation


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

You are given strings SS and TT consisting of lowercase English letters.

You can perform the following operation on SS any number of times:

Operation: Choose two distinct lowercase English letters c1c1 and c2c2, then replace every occurrence of c1c1 with c2c2, and every occurrence of c2c2 with c1c1.

Determine if SS and TT can be made equal by performing the operation zero or more times.

Constraints

  • 1≤|S|≤2×1051≤|S|≤2×105
  • |S|=|T||S|=|T|
  • SS and TT consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS
TT

Output

If SS and TT can be made equal, print Yes; otherwise, print No.


Sample Input 1 Copy

Copy

azzel
apple

Sample Output 1 Copy

Copy

Yes

azzel can be changed to apple, as follows:

  • Choose e as c1c1 and l as c2c2. azzel becomes azzle.
  • Choose z as c1c1 and p as c2c2. azzle becomes apple.

Sample Input 2 Copy

Copy

chokudai
redcoder

Sample Output 2 Copy

Copy

No

No sequences of operation can change chokudai to redcoder.


Sample Input 3 Copy

Copy

abcdefghijklmnopqrstuvwxyz
ibyhqfrekavclxjstdwgpzmonu

Sample Output 3 Copy

Copy

Yes

题意:给两个字符串,可以进行一个操作:第一个字符串选一个字符,第二个字符串选一个字符,然后第一个字符串中的所有这个字符都会被替换成第二个字符串的这个字符,问能否使第一个字符串变成第二个字符串

想要变成第二个字符串,字符间必须是一一对应的关系

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int num[maxn];
int main()
{
    string stra;
    string strb;
    cin>>stra>>strb;
    int len=stra.size();
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[stra[i]]==-1)
        {
            num[stra[i]]=strb[i];
        }
        else
        {
            if(num[stra[i]]!=strb[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[strb[i]]==-1)
        {
            num[strb[i]]=stra[i];
        }
        else
        {
            if(num[strb[i]]!=stra[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值