Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- #include <string>
- #include <fstream>
- using namespace std;
- ifstream fin("smiles.in");
- ofstream fout("smiles.out");
- int main() {
- int n; fin >> n;
- string z;
- getline(fin, z);
- for (int j = 0; j < n; j++) {
- getline(fin, z);
- bool ok = true;
- deque<int> deq;
- for (int i = 0; i < z.size(); i++) {
- if (z[i] == '(' || z[i] == '[' || z[i] == '{') {
- deq.push_back(z[i]);
- }
- else if (z[i] == ')' || z[i] == ']' || z[i] == '}') {
- if (i != 0 && z[i - 1] == ':') {
- //cout << "lol";
- continue;
- }
- if (deq.empty()) {
- fout << 1 << "\n";
- ok = false;
- break;
- }
- else {
- int x = deq.back();
- // cout << x << " " << z[i];
- int cnt = 0;
- if (z[i] == ')') {
- cnt = 1;
- }
- else {
- cnt = 2;
- }
- if (z[i] == x + cnt) {
- deq.pop_back();
- continue;
- }
- else {
- fout << 2 << "\n";
- ok = false;
- break;
- }
- }
- }
- }
- if (ok && !deq.empty()) {
- fout << 3 << "\n";
- }
- else if (ok&&deq.empty()) {
- fout << 0 << "\n";
- }
- }
- fin.close();
- fout.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement