Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <algorithm>
  6.  
  7.  
  8. int main()
  9. {
  10.     setlocale(LC_ALL, "Rus");
  11.     int variable;
  12.     std::ifstream input("input.txt");
  13.     std::string line;
  14.     int n = 0;
  15.     while (std::getline(input, line))
  16.     {
  17.         std::for_each(line.begin(), line.end(), [&n](const char &c)
  18.         {
  19.             if (c == '(') n++;
  20.             if (c == ')') n--;
  21.         }
  22.         );
  23.     }
  24.     if (n == 0) std::cout << " verno" << std::endl;
  25.     else
  26.     {
  27.         std::cout << "ne verno" << std::endl;
  28.         if (n > 0)
  29.         {
  30.             std::cout << " Не хватает " << n << " закрывающих скобок(скобки)";
  31.         }
  32.         if (n < 0) {
  33.             std::cout << " Не хватает " << abs(n)  << " открывающих скобок(скобки)";
  34.         }
  35.  
  36.     }
  37.     input.close();
  38.     system("pause");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement