Three numbers are given: a, b, c and an array of characters whose length is not more than 1000; It is necessary to go through all possible cases so that these three numbers constitute a given array of characters. These numbers are in order. Accordingly, a, b, c will also be arrays of characters.

For example: It is given 120234 Possible cases: a - 1 b - 20 c - 234. a - 1 b - 202 c - 34. a - 1 b - 2023 c - 4. a - 12 b - 0 c - 234. and so on.

  • Study assignments are allowed as questions only under the condition that you tried to solve them yourself before asking a question. Please edit the question and indicate what caused you difficulties in solving the problem. For example, provide the code you wrote when trying to solve a problem. - cpp questions
  • one
    An array of three, i.e. Your task is to find 2 boundaries between them (2 boundaries are determined). We start 2 nested loops: i = 0..len and j = i..len in it, there may be variations depending on whether the arrays can be empty or must contain at least one element. Then everything is simple, take the slices: a = s [0, i], b = [i, j], c = [j, len] - Andrey NOP

1 answer 1

Just split the length into 3 numbers - the lengths of the substrings.

string s = "1353121312"s; for(int la = 1; la < s.length()-1; ++la) { for(int lb = 1; lb < s.length()-la; ++lb) { int lc = s.length() - la - lb; cout << s.substr(0,la) << " " << s.substr(la,lb) << " " << s.substr(la+lb) << endl; } } }