📄 main.cpp
字号:
#include <iostream.h>
#include "stack.cpp" //Attention especially for template
void main()
/*
Post: The program has notified the user of any bracket
mismatch in the standard input file.
Uses: The class Stack.
*/
{
MyStack<char> openings;
char symbol;
bool is_matched = true;
cout << "Bracket Matching Program." << endl << "Input a string line:" << endl;
while (is_matched && (symbol = cin.get()) != '\n') {
if (symbol == '{' || symbol == '(' || symbol == '[')
openings.push(symbol);
if (symbol == '}' || symbol == ')' || symbol == ']') {
if (openings.empty()) {
cout << "2.Unmatched closing bracket " << symbol
<< " detected." << endl;
is_matched = false;
}
else {
char match;
openings.top(match);
openings.pop();
is_matched = (symbol == '}' && match == '{')
|| (symbol == ')' && match == '(')
|| (symbol == ']' && match == '[');
if (!is_matched)
cout << "Bad match " << match << symbol << endl;
}
}
}
if (!openings.empty())
cout << "1.Unmatched opening bracket(s) detected." << endl;
else
if (is_matched) cout << "0. Ok, matched!" << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -