题解
2023-09-01 10:40:19
发布于:广东
2阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string s, t;
getline(cin, s);
getline(cin, t);
vector<int> freqsS(26, 0);
vector<int> freqsT(26, 0);
for (char letter : s) {
freqsS[letter - 'a']++;
}
for (char letter : t) {
freqsT[letter - 'a']++;
}
vector<vector<bool>> compatible(26, vector<bool>(26, false));
for (char y = 'a'; y <= 'z'; y++) {
for (char x = 'a'; x < y; x++) {
string sRestricted;
string tRestricted;
for (char letter : s) {
if (letter == x || letter == y) {
sRestricted += letter;
}
}
for (char letter : t) {
if (letter == x || letter == y) {
tRestricted += letter;
}
}
compatible[x - 'a'][y - 'a'] = (sRestricted == tRestricted);
}
}
int q;
cin >> q;
string out;
while (q > 0) {
string subset;
cin >> subset;
char answer = 'Y';
int sSum = 0;
int tSum = 0;
for (char x : subset) {
sSum += freqsS[x - 'a'];
tSum += freqsT[x - 'a'];
}
if (sSum != tSum) {
answer = 'N';
}
for (int j = 0; j < subset.length(); j++) {
for (int k = j + 1; k < subset.length(); k++) {
if (!compatible[subset[j] - 'a'][subset[k] - 'a']) {
answer = 'N';
}
}
}
out += answer;
q--;
}
cout << out << endl;
return 0;
}
这里空空如也
有帮助,赞一个