题解 | #查找兄弟单词#

查找兄弟单词

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

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

using namespace std;

bool isBrother(string a, string b) {
    if (a != b) {
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        return a == b;
    } else {
        return false;
    }
}

int main() {
    int n, k;
    string x;
    vector<string> strs;
    multiset<string> Set;

    cin >> n;
    while (n--) { 
        string str;
        cin >> str;
        strs.push_back(str);
    }

    cin >> x;
    cin >> k;

    for (string s : strs)
        if (isBrother(s, x))
            Set.insert(s);

    cout << Set.size() << endl;
    if (k >= 1 && k <= Set.size()) {
        set<string>::iterator iter = Set.begin();
        while (--k)
            iter++;
        cout << *iter << endl;
    }
}
全部评论

相关推荐

05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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