时间限制:
10000ms
单点时限:
1000ms
内存限制:
256MB
描述
已知替换函数replace(c1, c2)的作用是把一个字符串中所有的c1字符替换成c2字符。
请你判断能否使用replace函数将字符串S变成D。
你可以调用replace函数任意多次。
输入
输入包含多组数据。
第一行包含一个整数T,代表数据组数。
每组数据包含两行,分别是字符串S和D。
1 ≤ T ≤ 10
S和T都只包含小写字母,且1 ≤ |S| = |D| ≤ 1000
输出
对于每组数据输出YES或者NO,表示能否使用replace函数将字符串S变成D。
2 aaabb ccccc aaabbbbb cccccddd样例输出
YES NO
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
struct node {
int word1;
int flag;
char word2;
}jugde[1111];
map<char, char>A;
map<char, char>::iterator p;
string a, b;
bool Judge() {
for (int i = 0; a[i] != '\0'; ++i)
{
p = A.find(a[i]);
if (p != A.end() && p->second != b[i])
//如果字符被找到
return 0;
else A[a[i]] = b[i];
}
return 1;
}
int main() {
int t,f;
cin >> t;
while (t--) {
A.clear();
cin >> a >> b;
if (Judge())cout << "YES";
else cout << "NO";
cout << endl;
}
return 0;
}