题目

代码
#include <bits/stdc++.h>
using namespace std;int main()
{map<vector<int>, vector<string>> a;set<vector<int>> c;vector<int> initial(26, 0);c.insert(initial);ifstream infile("words.txt");string s;while (getline(infile, s)){vector<int> b(26, 0);for (size_t j = 0; j < s.size() - 1; j++)b[s[j] - 'a']++;a[b].push_back(s);}string e = "~";while (!c.empty()){set<vector<int>> temp_d;for (const auto &i : c){if (a.find(i) == a.end())continue;for (const string &j : a[i]){if (j.size() > e.size())e = j;else if (j < e)e = j;vector<int> k = i;k[j.back() - 'a']++;if (a.find(k) != a.end())temp_d.insert(k);}}c = temp_d;}cout << e;return 0;
}