题解 | #查找兄弟单词#

查找兄弟单词

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

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n,k;
    string x;
    cin>>n;
    vector<string> arr;
    for(int i=0;i<n;i++)
    {
        string tmp;
        cin>>tmp;
        arr.push_back(tmp);
    }    
    cin>>x;
    cin>>k;
    vector<string> res;
    int coun=0;
    string xx=x;
    sort(x.begin(),x.end());
    for(auto &t:arr)
    {
        string tmp=t;
        sort(tmp.begin(),tmp.end());
        if(x==tmp&&xx!=t)
        {
         //  auto it=find(res.begin(),res.end(),t);
          //  if(it!=res.end())
                //continue;
                ;
            coun++;
            res.push_back(t);
        }
    }
    cout<<coun<<endl;
    sort(res.begin(),res.end());
    if(k-1<res.size())
        cout<<res[k-1];
    return 0;

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

全部评论

相关推荐

03-31 17:43
重庆大学 Java
点赞 评论 收藏
分享
1jian10:48h没写面评会变成这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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