Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- #include <deque>
- #include <vector>
- #include <stdlib.h>
- #include <set>
- #include <iostream>
- using namespace std;
- int main() {
- ifstream in("input.txt");
- ofstream out("output.txt");
- int n;
- in >> n;
- for (int i = 0; i < n; i++) {
- //bool nx = true;
- string s;
- in >> s;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == '0' && s[i + 1] == '2') {
- out << "NO" << "\n";
- //nx = false;
- break;
- }
- if (s[i] == '1' && s[i + 1] == '0') {
- out << "NO" << "\n";
- //nx = false;
- break;
- }
- if (s[i] == '2' && s[i + 1] == '0' || s[i+1] == '1') {
- out << "NO" << "\n";
- //nx = false;
- break;
- }
- //if (nx == true) {
- int c0 = 0, c1 = 0, c2 = 0;
- for (int i = 0; i < s.size(); i++) {
- if (s[i] == '0') {
- c0++;
- }
- if (s[i] == '1') {
- c1++;
- }
- if (s[i] == '2') {
- c2++;
- }
- }
- if (c0 == c1 || c1 == c2 || c0 == c2) {
- out << "YES" << endl;
- }
- //}
- }
- }
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement