Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <malloc.h>
- #include <set>
- #include <cstring>
- using namespace std;
- int main() {
- int *a;
- int *b;
- string input;
- cin >> input;
- bool aIsNotFull = true;
- int aSize = 0;
- int bSize = 0;
- for(char& c : input) {
- int num = (int) (c - '0');
- if(aIsNotFull) {
- a = (int*) realloc(a, (aSize + 1) * sizeof(int));
- if(c != '_') {
- a[aSize++] = num;
- } else {
- aIsNotFull = false;
- continue;
- }
- } else {
- b = (int*) realloc(b, (bSize + 1) * sizeof(int));
- if(c != '_') {
- b[bSize++] = num;
- } else break;
- }
- }
- for(int i = 0; i < aSize; i++) {
- cout << a[i];
- }
- cout << "\n";
- for(int i = 0; i < bSize; i++) {
- cout << b[i];
- }
- set<int> perm;
- for(int i = 0; i < aSize; i++) {
- int curr = a[i];
- perm.insert(curr);
- for(int j = i + 1; j < aSize; j++) {
- curr = curr * 10 + a[j];
- perm.insert(curr);
- }
- }
- string result = "";
- for(int i = 0; i < bSize; i++) {
- int j = i;
- int curr = b[j];
- while(perm.count(curr) != 0 && j < bSize) {
- cout << curr;
- cout << " ";
- if(i + 1 == bSize)
- result = result + std::to_string(curr);
- else
- result = result + std::to_string(curr) + "_";
- curr = curr * 10 + b[++j];
- }
- }
- cout << "\n";
- cout << result;
- free(a);
- free(b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement