题解 | #查找兄弟单词#

查找兄弟单词

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

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxlen = 10;
int n, k;
string dic[maxn];
bool isbro[maxn] = {false};
string word;
int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        cin >> dic[i];
    }
    cin>>word;
    scanf("%d", &k);
    int len = word.length();
    sort(dic, dic+n);
    string work = word;
    for(int i = 0; i < n; i++)
    {
        if(dic[i] != word && dic[i].length() == len)
        {
            do{
                if(work == dic[i]){
                    isbro[i] = true;
                }
            }while(next_permutation(work.begin(), work.end()));
        }
    }

    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        if(isbro[i] == true)
        {
            cnt ++;
        }
    }
    cout << cnt <<endl;
    int temp = 0;
    for(int i = 0; i < n; i++)
    {
        if(isbro[i] == true)
        {
            temp ++;
        }
        if(temp == k){
            cout << dic[i];
            return 0;
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
09-23 10:11
点赞 评论 收藏
分享
选钝角的小学生很热爱...:佬,今天收到的嘛?我三面结束二十天了,没人联系😅。请问你base哪里啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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