题解 | #查找兄弟单词#

查找兄弟单词

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")

全部评论

相关推荐

no_work_no_life:深圳,充电宝,盲猜anker
点赞 评论 收藏
分享
牛客246576843号:建议简历对点优化,想做HR专门列出HR实习,想做运营专门列出运营实习,并且对点写出项目经历以及数据,同时在个人总结上可以多凸出和岗位的匹配度
点赞 评论 收藏
分享
阿里巴巴各部门年终奖开奖了,有人拿到了220w
真烦好烦真烦:拿命换钱呢,公司给你220万,肯定是因为你对公司的贡献大于220万,想想要多厉害多累才能达到
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务