题解 | #查找兄弟单词#
查找兄弟单词
http://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; string s; while(cin>>n && n){ vector<string> brother_words, words; string word, target_word, old_target_word; for(int i=0;i<n;i++){ cin>>word; words.push_back(word); } cin>>target_word; old_target_word = target_word; cin>>k; sort(target_word.begin(),target_word.end()); for(int i=0;i<words.size();i++){ string old_word =words[i]; //if(words[i].size()==4 && (words[i][0] == 'b'|| words[i][0] =='a')) cout<<words[i]<<endl; sort(words[i].begin(),words[i].end()); if(words[i] == target_word && old_word != old_target_word){ brother_words.push_back(old_word); //cout<<old_word<<endl; } } cout<<brother_words.size()<<endl; sort(brother_words.begin(),brother_words.end()); if(k<brother_words.size()){ cout<<brother_words[k-1]<<endl; } } return 0; }