题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
#include <iostream> using namespace std; #include <vector> #include <algorithm> int main() { int nInputNum = 0; cin >> nInputNum; vector<string> vecInput; while (nInputNum--) { string strInputWords; cin >> strInputWords; vecInput.push_back(strInputWords); } string strBroWords_ori; cin >> strBroWords_ori; vector<string> vecBroWords_new; //比较是否为bro for (string strVal : vecInput) { if (strBroWords_ori.size() == strVal.size() && strBroWords_ori != strVal) { vector<char> vecCharVal_new; vector<char> vecCharVal_ori; for (char chVal : strVal) { vecCharVal_new.push_back(chVal); } for (char chVal : strBroWords_ori) { vecCharVal_ori.push_back(chVal); } sort(vecCharVal_ori.begin(), vecCharVal_ori.end()); sort(vecCharVal_new.begin(), vecCharVal_new.end()); bool bCompareRes = true; vecCharVal_ori == vecCharVal_new ? bCompareRes = true : bCompareRes = false;//判断,直接用== if (bCompareRes) { vecBroWords_new.push_back(strVal); } } } int nInputIndex = 0; cin >> nInputIndex; sort(vecBroWords_new.begin(), vecBroWords_new.end()); vecBroWords_new.size()==0?cout << 0<< endl: cout << vecBroWords_new.size()<< endl << vecBroWords_new[nInputIndex-1] << endl; } // 64 位输出请用 printf("%lld")