Advertisement
labyyysosaaat

Untitled

Oct 21st, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <string>
  4. #include <fstream>
  5. using namespace std;
  6. ifstream fin("smiles.in");
  7. ofstream fout("smiles.out");
  8.  
  9. int main() {
  10. int n; fin >> n;
  11. string z;
  12. getline(fin, z);
  13. for (int j = 0; j < n; j++) {
  14. getline(fin, z);
  15. bool ok = true;
  16. deque<int> deq;
  17. for (int i = 0; i < z.size(); i++) {
  18.  
  19. if (z[i] == '(' || z[i] == '[' || z[i] == '{') {
  20. deq.push_back(z[i]);
  21. }
  22.  
  23. else if (z[i] == ')' || z[i] == ']' || z[i] == '}') {
  24. if (i != 0 && z[i - 1] == ':') {
  25. //cout << "lol";
  26. continue;
  27. }
  28.  
  29. if (deq.empty()) {
  30. fout << 1 << "\n";
  31. ok = false;
  32. break;
  33. }
  34. else {
  35. int x = deq.back();
  36. // cout << x << " " << z[i];
  37. int cnt = 0;
  38. if (z[i] == ')') {
  39. cnt = 1;
  40. }
  41. else {
  42. cnt = 2;
  43. }
  44. if (z[i] == x + cnt) {
  45. deq.pop_back();
  46. continue;
  47. }
  48. else {
  49. fout << 2 << "\n";
  50. ok = false;
  51. break;
  52. }
  53.  
  54. }
  55. }
  56. }
  57. if (ok && !deq.empty()) {
  58. fout << 3 << "\n";
  59. }
  60. else if (ok&&deq.empty()) {
  61. fout << 0 << "\n";
  62. }
  63. }
  64. fin.close();
  65. fout.close();
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement