C#编写程序判断给定的表达式字符串中的括号是否正确匹配(成对出现)
例如:
正确的字符串:{[{}{}]}[()],或{
{}{}},或者[]{}()
错误的字符串:{()}[),或{(}),或({[{
using System;
using System.Collections.Generic;
namespace _111
{
class Program
{
public static void Main(string[] args)
{
string exp = “{()}[{}][()]”;
if (isCorrect(exp))
{
Console.WriteLine(“正确”);
}
else
{
Console.WriteLine(“错误”);
}
Console.ReadKey();
}
public static bool isCorrect(string exp)
{
int a = 0;
List<int> l = new List<int>();
if (exp != null)
{
for (int i = 0; i < exp.Length; i++)
{
switch (exp[i])
{
case '{':
a = 3;
break;
case