Number Replacement

Number Replacement

 

An integer array a_1, a_2, \ldots, a_na1​,a2​,…,an​ is being transformed into an array of lowercase English letters using the following prodecure:

While there is at least one number in the array:

  • Choose any number xx from the array aa, and any letter of the English alphabet yy.
  • Replace all occurrences of number xx with the letter yy.

For example, if we initially had an array a = [2, 3, 2, 4, 1]a=[2,3,2,4,1], then we could transform it the following way:

  • Choose the number 22 and the letter c. After that a = [c, 3, c, 4, 1]a=[c,3,c,4,1].
  • Choose the number 33 and the letter a. After that a = [c, a, c, 4, 1]a=[c,a,c,4,1].
  • Choose the number 44 and the letter t. After that a = [c, a, c, t, 1]a=[c,a,c,t,1].
  • Choose the number 11 and the letter a. After that a = [c, a, c, t, a]a=[c,a,c,t,a].

After the transformation all letters are united into a string, in our example we get the string "cacta".

Having the array aa and the string ss determine if the string ss could be got from the array aa after the described transformation?

Input

The first line contains a single integer tt (1 \leq t \leq 10^3(1≤t≤103) — the number of test cases.

Then the description of the test cases follows.

The first line of each test case contains a single integer nn (1 \leq n \leq 501≤n≤50) — the length of the array aa and the string ss.

The second line of each test case contains exactly nn integers: a_1, a_2, \ldots, a_na1​,a2​,…,an​ (1 \leq a_i \leq 501≤ai​≤50) — the elements of the array aa.

The third line of each test case contains a string ss of length nn, consisting of lowercase English letters.

Output

For each test case, output "YES", if we can get the string ss from the array aa, and "NO" otherwise. You can output each letter in any case.

Sample 1

InputcopyOutputcopy
7
5
2 3 2 4 1
cacta
1
50
a
2
11 22
ab
4
1 2 2 1
aaab
5
1 2 3 2 1
aaaaa
6
1 10 2 9 3 8
azzfdb
7
1 2 3 4 1 1 2
abababb
YES
YES
YES
NO
YES
YES
NO

Note

The first test case corresponds to the sample described in the statement.

In the second test case we can choose the number 5050 and the letter a.

In the third test case we can choose the number 1111 and the letter a, after that a = [a, 22]a=[a,22]. Then we choose the number 2222 and the letter b and get a = [a, b]a=[a,b].

In the fifth test case we can change all numbers one by one to the letter a.

题解:判断相同数字对应位置的字母是否相同即可

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int  vn[55];
char  vc[55];
int main() 
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,f=1;
		cin>>n;
		char fn,fc;
		for(int i=0;i<n;i++)
		{
			cin>>vn[i];
		}
		for(int i=0;i<n;i++)
		{
			cin>>vc[i];
		}
		for(int i=0;i<n;i++)
		{
		
				fn=vn[i];
				fc=vc[i];
				for(int j=i;j<n;j++)
				{
					if(vn[j]==fn)
					{
						if(vc[j]!=fc)
						{
							cout<<"NO"<<endl;
							f=0;
							break;
						}
						
					}
				}
				//cout<<vn<<" "<<vc<<" "<<"f: "<<f<<endl;
				if(f==0)
				break;

		}
		if(f)
		{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linalw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值