题解 | 查找兄弟单词

查找兄弟单词

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;
}


全部评论

相关推荐

10-17 13:54
上海大学 运营
雾凇岛:这还说什么了,冲了兄弟们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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