Pair of brackets

Source: Internet
Author: User

Knowledge: The string is automatically added after the end of the acceptance. With scanf ("%s", &s), there is a problem with the function input string, that is, if a space is entered to assume that the string ends, the character after the space is processed as the next entry, but the Get () function will receive the entire string of input until it encounters a change in behavior.

SCANF cannot read carriage return and storage

SCANF cannot accept space, Tab tab, carriage return, etc.; And get can accept space, Tab tab and enter, etc.;

The scanf touches the null character in the buffer (Space, tab, enter, the newline will be truncated and added), and the get is to wait for the carriage return to truncate the string and add the

For example, "Hello world!" string length is 12 (the string is stored with the end of the auto-plus character) if you write "Hello \0world!" string length is 6 (space is also counted as a character)

sprintf (A, "%2.2s", a); The first 2 indicates that the resulting string is not more than 2 characters, and if the last one is populated with a string terminator, the second 2 means up to 2 characters in the subsequent string.

Now, with a sequence of parentheses, you should check that the line brackets are paired.

Input
The first line enters a number n (0<n<=100), which indicates that there are n sets of test data. The next n lines enter multiple sets of input data, each set of input data is a string s (S is less than 10000, and S is not an empty string), and the number of test data groups is less than 5 groups. Data guarantee S contains only "[", "]", "(", ")" Four characters
Output
The
output of each set of input data is one row, and if the parentheses contained in the string are paired, the output is yes, and no is output if not paired.         First:
the premise of pairing: the number of characters must be an even number
of
second: first and N pairs
second and N-1 pairs
Loop end condition is j-i==1

Pair of brackets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.