Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Stack {
- struct slovos {
- char wrd;
- slovos* next;
- slovos(char x, slovos* p) : wrd(x), next(p) {}
- };
- slovos* head;
- public:
- Stack() : head(0) {}
- bool Empty() { //проверка на пустоту стека
- return head == 0;
- }
- void Push(char data) { // добавляем элемент
- head = new slovos(data, head);
- }
- char Top() {
- return head->wrd;
- }
- /*char buk(int index) {
- char s = head->wrd;
- char h = s[s.length()-index-1];
- return h;
- }*/
- char Pop() {
- slovos* r = head;
- char i = r->wrd;
- head = r->next;
- delete r;
- return i;
- }
- };
- int main() {
- Stack t;
- string s;
- in >> s;
- bool g = true;
- for (int i = 0; i < s.length(); i++) {
- char c = s[i];
- if (c == '(' || c == '[' || c == '{') {
- t.Push(s[i]);
- }
- else if (c == ')' || c == ']' || c == '}') {
- char top = t.Top();
- if (t.Empty()) {
- g = false;
- }
- else if ((c == ')' && top != '(') || (c == '}' && top != '{') || (c == ']' && top != '[')) {
- g = false;
- }
- }
- }
- if (g) { out << "Yes"; }
- else { out << "No"; }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement