console.log("我在编程中国学JavaScript\n");



var inputStrings = ['[','[]', '{}', '()', '{[]}', '{[]', '[{}]', '{[[]]}', '[{{}}]', '[]{}()', '[{]'];

function validateLegalString(inputString) {
    var legalString = ['(', '[', '}'];
    var inputChars = inputString.split('');
    let equalNum = 0;
    for (var i = 0; i < inputChars.length; i++) {
        var sIndex = i;
        var eIndex = inputChars.length - i - 1;
        if (inputChars[sIndex] === inputChars[eIndex]) {
            equalNum ++;
        }
    }
    
    console.log('equalNum:', equalNum);
    return equalNum == Math.ceil(inputChars.length / 2);
}

inputStrings.forEach(function(item,index,arr){
	if (validateLegalString(item)) {
	   console.log(`输入s=${item}是合法的`); 
	} else {
	   console.log(`输入s=${item}是不合法的`); 
	}
})