Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // Se dau n șiruri de paranteze rotunde. Să se stabilească, despre fiecare șir, dacă este corect parantezat – adică dacă parantezele se închid corect.
  2.  
  3. #include <fstream>
  4. #include <cstring>
  5. #include <stack>
  6.  
  7. using namespace std;
  8.  
  9. ifstream fin("prntz.in");
  10. ofstream fout("prntz.out");
  11.  
  12. int n;
  13. stack<char> St;
  14.  
  15.  
  16. int main()
  17. {
  18. fin >> n;
  19.  
  20. char t[25];
  21. for (int i = 0; i < n; i ++)
  22. {
  23. fin >> t;
  24.  
  25. for (int j = 0; j < strlen(t); j ++)
  26. if (t[j] == '(')
  27. St.push(t[j]);
  28. else
  29. St.pop();
  30.  
  31. if (St.empty())
  32. fout << 1 << endl;
  33. else
  34. fout << 0 << endl;
  35. }
  36.  
  37. fin.close();
  38. fout.close();
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement