Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <cstring>
- using namespace std;
- int main()
- {
- ifstream fin;
- ofstream fout;
- char str[501],
- str1[500];
- str[0] = 'a';
- char sign;
- int counter = 0;
- //int ocounter = 0;
- //int ccounter = 0;
- bool result = 1;
- fin.open("brackets.in");
- fout.open("brackets.out");
- fin >> str;
- while(str[0] != ' ')
- {
- /* if (str[0] != '(' && str[0] != '[')
- {
- result = 0;
- break;
- }*/
- for(int i = 0; i < strlen(str); i++)
- {
- sign = str[i];
- //fout << str1[counter - 1];
- if((sign == '(') || (sign == '['))
- str1[counter++] = sign;
- else if ((sign == ')' && str1[counter - 1] == '(') || ((sign == ']' && str1[counter - 1] == '[')))
- {
- counter--;
- }
- else if ((sign == ')' && str1[counter - 1] != '(') || ((sign == ']' && str1[counter - 1] != '[')))
- {
- result = 0;
- break;
- }
- }
- //fout << (result? "YES": "NO") << endl;
- str[501] = 'a';
- fin >> str;
- fout << str << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement