SHARE
TWEET

Untitled

a guest Nov 12th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma comment (linker, "/STACK:64000000")
  2. #include<iostream>
  3. #include<fstream>
  4. #include<stack>
  5. #include<functional>
  6. #include<algorithm>
  7. #include<vector>
  8. #include<cstdlib>
  9.  
  10. std::ifstream fin("input.txt");
  11. std::ofstream fout("output.txt");
  12.  
  13. int func(std::vector<char> v, std::stack<char> s){
  14.     for (int i = 0; i < v.size(); i++) {
  15.         char c = v[i];
  16.         switch (c) {
  17.         case '(': case '{': case '[':
  18.             s.push(c);
  19.             break;
  20.         case ')': case '}': case ']':
  21.             if (s.empty() || (c == ')' && s.top() != '(') ||
  22.                 (c == '}' && s.top() != '{') || (c == ']' && s.top() != '[') ) {
  23.                 if (i == 0)
  24.                     return -1;
  25.                 return i;
  26.             }
  27.             s.pop();
  28.             break;
  29.         }
  30.     }
  31.     if (s.size() != 0)
  32.         return v.size();
  33.     else
  34.     return s.size();
  35. }
  36. int main() {
  37.     char c;
  38.     std::stack<char> s;
  39.     int kolv=0;
  40.     std::vector<char> vect;
  41.     fin >> c;
  42.     while (!fin.eof())
  43.     {
  44.         vect.push_back(c);
  45.         fin >> c;
  46.     }
  47.     int res = func(vect, s);
  48.     if (res==0) {
  49.         fout << "YES";
  50.         std::cout << "YES";
  51.     }
  52.     else {
  53.         fout << "NO"<<"\n";
  54.         std::cout << "NO" << std::endl;
  55.         if (res != -1){
  56.             int kol = res;
  57.             fout << kol;
  58.             std::cout << kol<<std::endl;
  59.         }
  60.         else {
  61.             std::cout << 0<<std::endl;
  62.             fout << 0;
  63.         }
  64.     }
  65.  
  66.     system("pause");
  67.     return 0;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top