题解 | #查找兄弟单词#

查找兄弟单词

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

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

int main() {
    int len;
    cin>>len;
    int count = len;
    vector<string> dict;
    while(count--)
    {
        string temp;
        cin>> temp;
        dict.push_back(temp);
    }
    string target;
    cin>>target;
    int index;
    cin>>index;
    vector<int> hashTar(26,0);
    vector<string>result;
    for(auto i:target)
    {
        hashTar[i-97] ++; 
    }
    for(int i = 0; i < len; i++)
    {
        vector<int> hash(26,0);
        if(dict[i].size()==target.size())
        {
            if(dict[i]!=target)
            {
                for(auto ch:dict[i])
                    hash[ch-97]++;
                bool flag = true;
                for(int j = 0; j < 26;j++)
                {
                    if(hashTar[j]!=hash[j])
                        flag = false;
                }
                if(flag)
                {
                    result.push_back(dict[i]);
                }
            }  
        }
    }
    sort(result.begin(),result.end());
    if(result.size()==0)
        cout<<0;
    else
        cout<<result.size()<<endl<<result[index-1];

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

全部评论

相关推荐

我的人生算是废了,23届裸辞空档一年,存款只能坚持几个月了,找不到像样的工作了,人生何去何从。
梦想是成为七海千秋:这大环境下为什么要裸辞呀,风险真的挺大的,而且社招的话23届没有太多的竞争力,不过既然已经裸辞了就不要焦虑慢慢找。
点赞 评论 收藏
分享
06-18 15:03
重庆大学 运营
运营你豪哥:做一下被打的数据,分析输出优化建议
点赞 评论 收藏
分享
06-11 13:34
门头沟学院 C++
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
感觉自己陷入了死循环,因为不知道简历写什么所以什么也不想做,然后又什么都没做所以没得写。从三月到六月,三个月啊
零壹超人:没有简历 ➜ 不找项目 ➜ 没内容写 ➜ 更没简历 ➜ … 无限循环。你陷入了死锁,随便打破死锁的四个条件之一就可以了,打破循环等待,立即开始行动,不要等待;破坏占有且等待,立即抄一份简历先把简历写出来,再一点一点学简历上的东西
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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