Advertisement
Okorosso

fucking shit

Apr 4th, 2021
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. struct myPair {
  6.     std::string replaceStr;
  7.     std::string toReplace;
  8. };
  9.  
  10. bool myComp(const myPair& a, const myPair& b) {
  11.     return a.replaceStr < b.replaceStr;
  12. }
  13.  
  14.  
  15. std::string genStrWithLowestLen(std::string toGen, std::vector<myPair> v) {
  16.     using namespace std;
  17.     string tmp;
  18.     string smallestStr = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  19.     do {
  20.         tmp = toGen;
  21.         int left = -1;
  22.         for (int i(0); i < v.size(); ++i) {
  23.             left = tmp.find(v[i].replaceStr, left + 1);
  24.             while (left != -1) {
  25.                 tmp.replace(left, v[i].replaceStr.length(), v[i].toReplace);
  26.                 left = tmp.find(v[i].replaceStr, left + 1);
  27.             }
  28.         }
  29.         int l1 = tmp.length(), l2 = smallestStr.length();
  30.  
  31.         if (l1 < l2 and !tmp.empty()) {
  32.             smallestStr = tmp;
  33.         }
  34.         tmp = "";
  35.     } while (next_permutation(v.begin(), v.end(), myComp));
  36.     if (smallestStr.length() < 255)
  37.         return smallestStr;
  38.     return toGen;
  39.     return " ";
  40. }
  41.  
  42. int main() {
  43.     using namespace std;
  44.  
  45.     int replaceStrCount, stringCount;
  46.     cin >> replaceStrCount >> stringCount;
  47.     vector<myPair> vec(replaceStrCount);
  48.     string a;
  49.     getline(cin, a);
  50.     for (int i = 0; i < replaceStrCount; i++) {
  51.         string tmp;
  52.  
  53.         getline(cin, tmp);
  54.         vec[i].replaceStr = tmp;
  55.         getline(cin, tmp);
  56.         vec[i].toReplace = tmp;
  57.     }
  58.     string resultStr;
  59.  
  60.     for (int i = 0; i < stringCount; i++) {
  61.         string tmpStr;
  62.         getline(cin, tmpStr);
  63.         if (tmpStr.empty()) {
  64.             resultStr += '\n' + tmpStr;
  65.         }
  66.         resultStr += "\n" + genStrWithLowestLen(tmpStr, vec);
  67.     }
  68.     cout << resultStr;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement