C++ 判断字符串是否为通配符变位词
#include
bool isWildcardAnagram(string s1, string s2) { // 将字符串s1和s2排序 sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end());
// 判断排序后的字符串是否相等
if (s1 == s2) {
return true;
} else {
return false;
}
}
int main() { string s1, s2; cin >> s1 >> s2;
if (isWildcardAnagram(s1, s2)) {
cout << 'A' << endl;
} else {
cout << 'N' << endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qvpI 著作权归作者所有。请勿转载和采集!