题解 | #查找兄弟单词#

查找兄弟单词

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

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool myfunction(char a,char b){return a<b;}
bool str_function(string a,string b){return a<b;}
int main() {
    int num;
    int k;
    vector<string> dic;
    string word;
    int p=0;
    cin>>num;
    //dic.resize(num,"");
    for(int i=0;i<num;i++){
        string temp;
        cin>>temp;
        dic.push_back(temp); 
    }
    cin>>word;
    cin>>k;
    int size=word.size();
    string orign_word=word;
    vector<string> same_word;
    sort(word.begin(),word.end(),myfunction);
    for(int i=0;i<num;i++){
        if(dic[i].size() != size || dic[i] == orign_word){
            continue;
        }
        string orign_dic=dic[i];
        sort(dic[i].begin(), dic[i].end(),myfunction);
        if(dic[i] == word){
            same_word.push_back(orign_dic);
        }

    }
    sort(same_word.begin(),same_word.end(),str_function);
    if(same_word.size()==0){
        cout<<same_word.size()<<endl;
    }else{
        cout<<same_word.size()<<endl;
         cout<<same_word[k-1]<<endl;
    }
    
   
    return 0;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

10-16 15:48
算法工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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