题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isbrother(string s1, string s2) { //排序判断
if (s1.size() == s2.size()) {
if (s1 == s2)
return false;
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
if (s1 == s2)
return true;
}
return false;
}
int main() {
int n;
cin >> n;
vector<string> res;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
res.push_back(s);
}
string x;
cin >> x;
int k;
cin >> k;
vector<string> ans;
for(auto s : res)
{
if(isbrother(s, x))
{
ans.push_back(s);
}
}
cout << ans.size() << endl;
sort(ans.begin(), ans.end());
if(ans.size() >= k)
{
cout << ans[k-1] << endl;
}
}
// 64 位输出请用 printf("%lld")
嘉士伯公司氛围 714人发布