Advertisement
Kostiggig

Untitled

Mar 4th, 2023
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <set>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. int main() {
  9.     int *a;
  10.     int *b;
  11.     string input;
  12.     cin >> input;
  13.     bool aIsNotFull = true;
  14.  
  15.     int aSize = 0;
  16.     int bSize = 0;
  17.     for(char& c : input) {
  18.         int num = (int) (c - '0');
  19.         if(aIsNotFull) {
  20.             a = (int*) realloc(a, (aSize + 1) * sizeof(int));
  21.            
  22.             if(c != '_') {
  23.                 a[aSize++] = num;
  24.             } else {
  25.                 aIsNotFull = false;
  26.                 continue;
  27.             }
  28.         } else {
  29.             b = (int*) realloc(b, (bSize + 1) * sizeof(int));
  30.            
  31.             if(c != '_') {
  32.                 b[bSize++] = num;
  33.             } else break;
  34.         }
  35.     }
  36.    
  37.     for(int i = 0; i < aSize; i++) {
  38.         cout << a[i];
  39.     }
  40.    
  41.     cout << "\n";
  42.    
  43.     for(int i = 0; i < bSize; i++) {
  44.         cout << b[i];
  45.     }
  46.    
  47.     set<int> perm;
  48.     for(int i = 0; i < aSize; i++) {
  49.         int curr = a[i];
  50.         perm.insert(curr);
  51.         for(int j = i + 1; j < aSize; j++) {
  52.             curr = curr * 10 + a[j];
  53.             perm.insert(curr);
  54.         }
  55.     }
  56.  
  57.     string result = "";
  58.     for(int i = 0; i < bSize; i++) {
  59.         int j = i;
  60.         int curr = b[j];
  61.         while(perm.count(curr) != 0 && j < bSize) {
  62.             cout << curr;
  63.             cout << " ";
  64.             if(i + 1 == bSize)
  65.                 result = result + std::to_string(curr);
  66.             else
  67.                 result = result + std::to_string(curr) + "_";
  68.             curr = curr * 10 + b[++j];
  69.         }
  70.     }
  71.    
  72.     cout << "\n";
  73.     cout << result;
  74.    
  75.     free(a);
  76.     free(b);
  77.        
  78.     return 0;
  79. }
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement