#include #include #include #include #include using namespace std; void PrintAnswer(const string& s) { int offset = 0; while (offset < (int)s.size()){ cout << s.substr(offset, min(72, (int)(s.size() - offset))) << endl; offset += 72; } cout << endl; } main() { string in; while (getline(cin, in) && in != ""){ string s; s += in; while (getline(cin, in) && in != ""){ s += in; } //cout << s << endl; string target; getline(cin, target); getline(cin, in); int use[128]; memset(use, 0, sizeof(use)); for (int i = 0; i < (int)target.size(); ++i){ use[target[i]] = true; } sort(target.begin(), target.end()); target.erase(unique(target.begin(), target.end()), target.end()); deque table[1024]; deque junban; //junban.reserve(s.size()); for (string::iterator it_s = s.begin(); it_s != s.end(); ++it_s){ if (use[*it_s]){ table[*it_s].push_back((int)distance(s.begin(), it_s)); junban.push_back(*it_s); //cout << s[i]; } } int min_length = INT_MAX; int from = INT_MAX; int to = 0; bool is_failed = false; for (string::iterator it_target = target.begin(); it_target != target.end(); ++it_target){ if (table[*it_target].empty()){ is_failed = true; break; } int pos = table[*it_target].front(); from = min(from, pos); to = max(to, pos); } if (is_failed){ cout << 0 << endl << endl; continue; } int answer_from = from; int answer_to = to; min_length = min(min_length, to - from); int last_from = from; int number = 1; while (!junban.empty()){ char now = junban.front(); junban.pop_front(); table[now].pop_front(); if (table[now].empty()){ break; } to = max(to, table[now].front()); char next = junban.front(); from = table[next].front(); if (min_length > to - from){ min_length = to - from; answer_from = from; answer_to = to; number = 1; last_from = from; } else if (min_length == to - from && from != last_from){ ++number; } } cout << number << endl << endl; PrintAnswer(s.substr(answer_from, answer_to - answer_from + 1)); } }