题解 | #查找兄弟单词#

查找兄弟单词

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

全部评论

相关推荐

10-11 17:30
湖南大学 C++
我已成为0offer的糕手:羡慕
点赞 评论 收藏
分享
10-09 22:05
666 C++
找到工作就狠狠玩CSGO:报联合国演讲,报电子烟设计与制造
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务