Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <string>#include <iostream>#include <map>using namespace std;int main() {string s;int n,m;map<long long,string> shortest,longest;map<string,long long> dict;cin >> s >> n;m = s.length();for(int i = 0; i < m; i++) {for(int j = 1; j <= m-i; j++) {string x = s.substr(i,j);long long st = 0;for(int k = 0; k <= m-j; k++) {if(x==s.substr(k,j)) {st |= (1LL<<(k+j));}}if(shortest[st].length()==0 || j < (int)shortest[st].length()) {shortest[st] = x;}if(j > (int)longest[st].length()) {longest[st] = x;}dict[x] = st;}}