Advertisement
Spocoman

05. Mathematical Expression

Oct 29th, 2023 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string str;
  8.     getline(cin, str);
  9.  
  10.     int openBrackets = 0;
  11.  
  12.     for (int i = 0; i < str.length(); i++) {
  13.         if (str[i] == '(') {
  14.             openBrackets++;
  15.         }
  16.         else if (str[i] == ')') {
  17.             openBrackets--;
  18.         }
  19.         if (openBrackets < 0) {
  20.             break;
  21.         }
  22.     }
  23.  
  24.     cout << (openBrackets == 0 ? "correct" : "incorrect") << endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement