Nonoyes
When you get to the topic, the most thought of course is the bracket matching question, and did not think about the other. Here's my thought process:
Write an example of a long brace match to find the pattern. As follows:
[([()])()]
Ecstatic, found the following pattern:
1. If the length of the string is odd, it is not possible to match the string. So the strlen () function is used.
2. For an even-numbered condition, start looking for the first character. Find the first one, then find the second one:
If the first and second mismatches indicate that the last bracket is definitely a match, the match is started. (etc.).
When in-depth analysis, found that, well, the model is too idealistic, no. There are serious errors that will only be satisfied if the brackets are fully axisymmetric in the center, PASS.
So, I thought about the other, finally, considering the idea of recursion + elimination, thought of a great idea:
1. Recursion---resolves to the minimum solution;
2. I'm done with the match.
This is always the case in parentheses matching: () or []. When this part is eliminated, the rest of the section will always appear () or [].
So, is it possible to eliminate this as a unit until the end of the entire sequence is eliminated? I think it should be possible.
But how do you implement this part? In what way to achieve, but also a headache problem.
This reminds me of playing music when the "Rhythm Bar" (Let's call it), can be large, can be small, and finally can not.
So, I need two pieces.
1. String header address pointer.
2. Move the pointer.
Always feel a little bit less what, how to express the deletion of the character? Can it be represented in the original string? is a problem again. Need to solve, so think of other solutions:
Starting with the first bit in the string sequence, one judgement, using the "FILO" way to represent, so there are the following ideas:
1. Set the element to a stack, and if the element that is going into the stack matches the top element of the stack, the top element of the stack pops up.
2. Traverse the entire string, and when the traversal is over, determine the current stack bottom and where the stack tops are. If equal, the description matches, otherwise.
Why can't we introduce the error-judging mechanism in the middle?
We can divide these matching elements into two categories:
The class is left and the class is right . (Isn't that nonsense?) )
However, it detects that the elements and top elements of the stack are not in the same class and do not match . Then, we have the right to say: Do not check, this string killed me, I will say no.
If the stack operation is esoteric, you can use an outer array (that is, an array) as a cache buff to delete elements.
So, here's the following:
1. Determine the length of the current string.
2. Copy a string from the first character to the buff.
3. Error-Judging mechanism, if it is in a different class, and matches, then initialize the value at the current index and the dynamic index value of the array element-1.
4. In the meantime, there is no error, and the current string is processed, otherwise no.
5.ok, no problem, return yes.
Above, only solves the string match problem, and also has the output rendering.
All right!!! Output rendering is a number of groups, can be processed in real time?
Ideas:
The result of comparing each row has a result buffer, and finally loops through the output.
20150910, bad code.