⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matchbrackets.cpp

📁 关于栈的操作的小程序
💻 CPP
字号:
// MatchBrackets.cpp : implementation file
//

#include "stdafx.h"
#include "CStackOperation.h"
#include "MatchBrackets.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMatchBrackets dialog


CMatchBrackets::CMatchBrackets(CWnd* pParent /*=NULL*/)
	: CDialog(CMatchBrackets::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMatchBrackets)
	m_strExpr = _T("");
	m_strResult = _T("");
	//}}AFX_DATA_INIT
}


void CMatchBrackets::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMatchBrackets)
	DDX_Text(pDX, IDC_EXPRESSION, m_strExpr);
	DDX_Text(pDX, IDC_RESULT, m_strResult);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMatchBrackets, CDialog)
	//{{AFX_MSG_MAP(CMatchBrackets)
	ON_BN_CLICKED(IDC_JUDGE, OnJudge)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMatchBrackets message handlers

void CMatchBrackets::OnJudge() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	s.Clear();
	char x;
	CString str = m_strExpr;
	int len = str.GetLength();
	for(int i=0; i<len; i++)
	{
		char c = str.GetAt(i);
		if(c == '(' || c == '[' || c == '{')
		{
		s.Push(c);
		}
		else if(c==']')
		{
			x = s.Pop();
			if(x != '[')
			{
				m_strResult = "括号不匹配!";
				UpdateData(FALSE);
				return;
			}
		}
		else if(c==')')
		{
			x = s.Pop();
			if(x != '(')
			{
				m_strResult = "括号不匹配!";
				UpdateData(FALSE);
				return;
			}
		}
		else if(c=='}')
		{
			x = s.Pop();
			if(x != '{')
			{
				m_strResult = "括号不匹配!";
				UpdateData(FALSE);
				return;
			}
		}
	}
	if(s.IsEmpty())
	{
		m_strResult = "括号匹配!";
	}
	else
	{
		m_strResult = "括号不匹配!";
	}
	UpdateData(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -