题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isBro(string s, string s2) {
if(s.size()==s2.size())
{
if(s==s2)
return false;
sort(s.begin(), s.end());
sort(s2.begin(), s2.end());
if(s==s2)
return true;
}
return false;
}
int main() {
int n;
while (cin >> n) { // 注意 while 处理多个 case
vector<string> v1(n);
for (int i = 0; i < n; i++) {
cin >> v1[i];
}
string str;
cin >> str;
int k;
cin >> k;
vector<string> bro;
for (int i = 0; i < v1.size(); i++) {
if(isBro(str, v1[i]))
bro.push_back(v1[i]);
}
sort(bro.begin(), bro.end());
cout<<bro.size()<<endl;
if(bro.size()>=k)
{
cout<<bro[k-1]<<endl;
}
}
return 0;
}
// 64 位输出请用 printf("%lld")
查看17道真题和解析