题解 | 查找兄弟单词

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
vector<string> sour;
vector<string> dst;

bool isBrother(string k, string s){
    if(k.length() != s.length() || k == s)  return false;
    sort(s.begin(),s.end());
    sort(k.begin(),k.end());
    return k == s;
}

int main(void){
    int n;
    cin >> n;
    while(n--){
        string tmp;
        cin >> tmp;
        sour.push_back(tmp);
    }
    string pat;
    cin >> pat;
    int k;
    cin >> k;
    for(auto elem : sour){
        if(isBrother(pat,elem)){
            dst.push_back(elem);
        }
    }
    
    sort(dst.begin(),dst.end());
    cout << dst.size() << endl;
    if(dst.size() >= k) cout << dst[k - 1] << endl;

    return 0;
}


全部评论

相关推荐

09-22 15:45
门头沟学院 Java
谁给娃offer我给...:我也遇到了,我说只要我通过面试我就去,实际上我根本就不会去😁
点赞 评论 收藏
分享
10-22 19:44
门头沟学院 Java
面了100年面试不知...:那我得去剪个头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务