Advertisement
StabCrab

Скобки

Mar 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     string a;
  6.     cin >> a;
  7.     int circle = 0;
  8.     int figure = 0;
  9.     int square = 0;
  10.     int triangle = 0;
  11.     for (int i = 0; i < a.length(); i++)
  12.     {
  13.         switch (a[i])
  14.         {
  15.             case '(':
  16.             {
  17.                 circle++;
  18.                 break;
  19.             }
  20.             case ')':
  21.             {
  22.                 circle--;
  23.                 break;
  24.             }
  25.             case '{':
  26.             {
  27.                 figure++;
  28.                 break;
  29.             }
  30.             case '}':
  31.             {
  32.                 figure--;
  33.                 break;
  34.             }
  35.             case '[':
  36.             {
  37.                 square++;
  38.                 break;
  39.             }
  40.             case ']':
  41.             {
  42.                 square--;
  43.                 break;
  44.             }
  45.             case '<':
  46.             {
  47.                 triangle++;
  48.                 break;
  49.             }
  50.             case '>':
  51.             {
  52.                 triangle--;
  53.                 break;
  54.             }
  55.             default:
  56.             {
  57.                 cout << "ERROR";
  58.                 return -1;
  59.             }
  60.         }
  61.     }
  62.     if (circle == 0 && figure == 0 && square == 0 && triangle == 0)
  63.         cout << "YES";
  64.     else
  65.         cout << "NO";
  66.     return 0;
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement