您的位置:首页 > 其它

文章标题

2017-03-23 09:46 218 查看
描述

题目描述

clip_image002.jpg

clip_image004.jpg

clip_image006.jpg

知识点 查找

运行时间限制 10M

内存限制 128

输入

先输入字典中单词的个数,再输入n个单词作为字典单词。

输入一个单词,查找其在字典中兄弟单词的个数

再输入数字n

输出

根据输入,输出查找到的兄弟单词的个数

输出指定的第n个兄弟单词

样例输入 3 abc bca cab abc 1

样例输出 2 bca

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_map>
#include<fstream>
#include<sstream>
#include<queue>
#include<stack>
using namespace std;
bool is_brother(string s1, string s2){
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
if (s1 == s2)
return true;
else
return false;
}
int main(){
int n;
while (cin >> n){
vector<string> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
string s, str;
int index;
int brother_num = 0;
cin >> s;
cin >> index;
for (int i = 0; i < v.size(); i++){
if (s != v[i]){
if (is_brother(s, v[i])){
brother_num++;
if (brother_num == index)
str = v[i];
}
}
}
cout << brother_num << endl;
if (brother_num >= index)
cout << str << endl;
v.clear();
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: