Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <string>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <iomanip>
  6. #include <fstream>
  7. #include <deque>
  8. #include <vector>
  9. #include <stdlib.h>
  10. #include <set>
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15.  
  16.  
  17.  
  18. int main() {
  19. ifstream in("input.txt");
  20. ofstream out("output.txt");
  21. int n;
  22. in >> n;
  23. for (int i = 0; i < n; i++) {
  24. //bool nx = true;
  25. string s;
  26. in >> s;
  27. for (int i = 0; i < s.size(); i++) {
  28. if (s[i] == '0' && s[i + 1] == '2') {
  29. out << "NO" << "\n";
  30. //nx = false;
  31. break;
  32. }
  33. if (s[i] == '1' && s[i + 1] == '0') {
  34. out << "NO" << "\n";
  35. //nx = false;
  36. break;
  37. }
  38. if (s[i] == '2' && s[i + 1] == '0' || s[i+1] == '1') {
  39. out << "NO" << "\n";
  40. //nx = false;
  41. break;
  42. }
  43. //if (nx == true) {
  44. int c0 = 0, c1 = 0, c2 = 0;
  45. for (int i = 0; i < s.size(); i++) {
  46. if (s[i] == '0') {
  47. c0++;
  48. }
  49. if (s[i] == '1') {
  50. c1++;
  51. }
  52. if (s[i] == '2') {
  53. c2++;
  54. }
  55. }
  56. if (c0 == c1 || c1 == c2 || c0 == c2) {
  57. out << "YES" << endl;
  58. }
  59. //}
  60. }
  61.  
  62. }
  63. in.close();
  64. out.close();
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement