Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 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. if (i != 0 && z[i - 1] == ':') {
  21. //cout << "lol";
  22. continue;
  23. }
  24. deq.push_back(z[i]);
  25. }
  26.  
  27. else if (z[i] == ')' || z[i] == ']' || z[i] == '}') {
  28. if (i != 0 && z[i - 1] == ':') {
  29. //cout << "lol";
  30. continue;
  31. }
  32.  
  33. if (deq.empty()) {
  34. fout << 1 << "\n";
  35. ok = false;
  36. break;
  37. }
  38. else {
  39. int x = deq.back();
  40. // cout << x << " " << z[i];
  41. int cnt = 0;
  42. if (z[i] == ')') {
  43. cnt = 1;
  44. }
  45. else {
  46. cnt = 2;
  47. }
  48. if (z[i] == x + cnt) {
  49. deq.pop_back();
  50. continue;
  51. }
  52. else {
  53. fout << 2 << "\n";
  54. ok = false;
  55. break;
  56. }
  57.  
  58. }
  59. }
  60. }
  61. if (ok && !deq.empty()) {
  62. fout << 3 << "\n";
  63. }
  64. else if (ok&&deq.empty()) {
  65. fout << 0 << "\n";
  66. }
  67. }
  68. fin.close();
  69. fout.close();
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement