Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fstream>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream fin;
  10.     ofstream fout;
  11.  
  12.     char str[501],
  13.          str1[500];
  14.     str[0] = 'a';
  15.     char sign;
  16.     int counter = 0;
  17.     //int ocounter = 0;
  18.     //int ccounter = 0;
  19.     bool result = 1;
  20.  
  21.     fin.open("brackets.in");
  22.     fout.open("brackets.out");
  23.     fin >> str;
  24.     while(str[0] != ' ')
  25.     {
  26.         /* if (str[0] != '(' && str[0] != '[')
  27.         {
  28.             result = 0;
  29.             break;
  30.         }*/
  31.  
  32.     for(int i = 0; i < strlen(str); i++)
  33.     {
  34.  
  35.  
  36.        sign = str[i];
  37.        //fout << str1[counter - 1];
  38.        if((sign == '(') || (sign == '['))
  39.             str1[counter++] = sign;
  40.  
  41.        else if ((sign == ')' && str1[counter - 1] == '(') || ((sign == ']' && str1[counter - 1] == '[')))
  42.        {
  43.            counter--;
  44.        }
  45.        else if ((sign == ')' && str1[counter - 1] != '(') || ((sign == ']' && str1[counter - 1] != '[')))
  46.        {
  47.            result = 0;
  48.            break;
  49.        }
  50.     }
  51.     //fout << (result? "YES": "NO") << endl;
  52.     str[501] = 'a';
  53.     fin >> str;
  54.     fout << str << endl;
  55.     }
  56.  
  57.  
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement