查找兄弟单词

查找兄弟单词

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

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n;
    string str, tarStr;
    vector<string> vec;
    while(cin >> n)
    {
        while(n--)
        {
            cin >> str;
            vec.push_back(str);
        }
        cin >> tarStr >> n;

        vector<string> rst;
        string temp1 = tarStr;
        sort(temp1.begin(), temp1.end());
        for(auto it = vec.begin(); it != vec.end(); ++it)
        {
            string temp2 = *it;
            sort(temp2.begin(), temp2.end());
            if(temp1 == temp2 && *it != tarStr) rst.push_back(*it);
        }
        sort(rst.begin(), rst.end());
        cout << rst.size() << endl;
        if(n <= rst.size()) cout << rst[n - 1] << endl;
    }

    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务