Matching of parentheses
/* Bracket matching problem: enter a number N (0 <N <= 100) In the first line, indicating that there are N groups of test data. * // * Multiple Input groups are input in N rows. Each group of input data is a string (S is less than 10000 characters in length and S is not an empty string ), * // * The number of test data groups is less than 5. Data guarantee S only contains four types of characters. Match the output yes. Otherwise, output no * // * author: dzw * // * date: * // * Resolution: Use a to indicate the number of left parentheses, matching a minus 1. therefore, when a = 0, the match is successful. * // * Special Case: if the first character after a successful match is a right brace, it is represented by ID B, at this time, no matter how many parentheses are followed, the matching is successful */# include <stdio. h> # include <string. h> int main () {int n, I, j; scanf ("% d", & n); int c [n]; char num [n] [1, 10000]; for (I = 0; I <n; I ++) {int a = 0, B = 1; scanf ("% s", num [I]); for (j = 0; j <strlen (num [I]); j ++) {switch (num [I] [j]) {case ')': if (a = 0) B = 0; if (num [I] [A-1] = '(') a-= 1; break; case ']': if (a = 0) B = 0; if (num [I] [A-1] = '[') a-= 1; break; case '(': num [I] [a] = num [I] [j]; A + = 1; break; case '[': num [I] [a] = num [I] [j]; a + = 1; break ;}} if (! = 0 | B = 0) c [I] = 0; else c [I] = 1 ;}for (I = 0; I <n; I ++) {if (c [I] = 0) printf ("no \ n"); else printf ("yes \ n");} return 0 ;}
You have passed the test, but cannot Accepted. I don't know why