-
Notifications
You must be signed in to change notification settings - Fork 0
/
C. String Equality.cpp
66 lines (62 loc) · 1.39 KB
/
C. String Equality.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
57
58
59
60
61
62
63
64
65
66
#include <fstream>
#include <string>
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
int t;
int n, k;
bool csort(pair<int, int> a, pair<int, int>b){
if (a.first == b.first){
return a.second < b.second;
}
else{
return a.first < b.first;
}
}
int main(){
cin >> t;
for (int z = 0; z < t; z++){
cin >> n >> k;
string a, b;
cin >> a >> b;
int fra[27];
int frb[27];
for (int x = 0; x < 27; x++){
fra[x] = 0;
frb[x] = 0;
}
for (int x = 0; x < n; x++){
int dig = a[x] - 'a';
int dig2 = b[x] - 'a';
fra[dig]++;
frb[dig2]++;
}
bool answer = true;
int i = 0;
while(true){
if (i >= 26){
break;
}
if (fra[i] > frb[i]){
if ((fra[i] - frb[i]) % k != 0){
answer = false;
}
fra[i + 1] += (fra[i] - frb[i]);
}
else if (fra[i] < frb[i]){
answer = false;
}
i++;
}
if (answer){
cout << "YES\n";
}
else{
cout << "NO\n";
}
}
}