-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunforgivable_curse.cpp
56 lines (56 loc) · 1.09 KB
/
unforgivable_curse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int main()
{
int cases;
cin>>cases;
for(int i=0; i<cases; i++)
{
int n,k;
cin>>n>>k;
string a, b;
cin>>a>>b;
if(a==b)
{
cout<<"Yes"<<endl;
continue;
}
// int xx = a.size();
int ini = max(0,n-1-k+1);
int fin = min(n-1,k-1);
bool ans=true;
if(ini<=fin)
{
for(int j=ini; j<=fin; j++)
{
if(a[j] != b[j])
{
ans=false;
break;
}
}
}
if(!ans)
{
cout<<"No"<<endl;
continue;
}
vector<int> aa(26,0);
vector<int> bb(26,0);
for(int j=0; j<a.size(); j++)
{
aa[a[j]-'a']++;
}
for(int j=0; j<b.size(); j++)
{
bb[b[j]-'a']++;
}
if(aa != bb)
{
cout<<"No"<<endl;
continue;
}
cout<<"Yes"<<endl;
continue;
}
}