#include <iostream> #include <string> #include <cmath> #include <algorithm> #include <stack> #include <vector> #include <set> #include <queue> using namespace std; int main() { int i, j, flag, k; int n, m, t; string str; string s1, s2; cin >> n; while (n--) { cin >> s1 >> s2 >> k; for (i = 0; i < s1.size(); ) { if (s1[i] == s2[i]) { s1.erase(i, 1); s2.erase(i, 1); } else i++; } t = 0; flag = 1; for (j = 0; j < s1.size(); ++j) { if (s1[j] != s2[j]) { int pos = s2.find(s2[j],j+1); if (pos == -1) { pos = s1.find(s2[j], j + 1); if (pos != -1) { swap(s1[j], s1[pos]); t++; } else { flag = 0; break; } } else { swap(s1[j], s2[pos]); t++; } } } if(flag==0) cout << "NO" << endl; else if (t <= k) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } |
Double click to view unformatted code.