题解 | #查找兄弟单词#

查找兄弟单词

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

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

int main() {
    int nInputNum = 0;
    cin >> nInputNum;
    vector<string> vecInput;
    while (nInputNum--) {
        string strInputWords;
        cin >> strInputWords;
        vecInput.push_back(strInputWords);
    }

    string strBroWords_ori;
    cin >> strBroWords_ori;
    vector<string> vecBroWords_new;

    //比较是否为bro
    for (string strVal : vecInput) {
        if (strBroWords_ori.size() == strVal.size() && strBroWords_ori != strVal) {
            vector<char> vecCharVal_new;
            vector<char> vecCharVal_ori;

            for (char chVal : strVal) {
                vecCharVal_new.push_back(chVal);
            }

            for (char chVal : strBroWords_ori) {
                vecCharVal_ori.push_back(chVal);
            }

            sort(vecCharVal_ori.begin(), vecCharVal_ori.end());
            sort(vecCharVal_new.begin(), vecCharVal_new.end());

            bool bCompareRes = true;
            vecCharVal_ori == vecCharVal_new ? bCompareRes = true : bCompareRes =
                        false;//判断,直接用==

            if (bCompareRes) {
                vecBroWords_new.push_back(strVal);
            }
        }
    }

    int nInputIndex = 0;
    cin >> nInputIndex;

    sort(vecBroWords_new.begin(), vecBroWords_new.end());

    vecBroWords_new.size()==0?cout << 0<< endl: cout << vecBroWords_new.size()<< endl <<  vecBroWords_new[nInputIndex-1] << endl;
   
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

12-03 18:53
海南大学 Java
华为 Java开发 25K*16
点赞 评论 收藏
分享
听说改名字就能收到offer哈:Radis写错了兄弟
点赞 评论 收藏
分享
尊尼获获:闺蜜在哪?
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务