Advertisement
bibaboba12345

Untitled

May 17th, 2022
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int N = 2e5;
  7.  
  8. string s, s1;
  9.  
  10. vector<string> elem;
  11.  
  12.  
  13.  
  14. bool IsUpper(char a) {
  15. return a >= 'A' && a <= 'Z';
  16. }
  17.  
  18. bool IsLower(char a) {
  19. return a >= 'a' && a <= 'z';
  20. }
  21.  
  22. bool IsNumber(char a) {
  23. return a >= '0' && a <= '9';
  24. }
  25.  
  26. int main()
  27. {
  28. cin >> s;
  29. int n = s.size();
  30. if (IsNumber(s[0])) {
  31. cout << "NO";
  32. return 0;
  33. }
  34. if (IsLower(s[0])) {
  35. cout << "NO";
  36. return 0;
  37. }
  38. if (s.size() == 1) {
  39. cout << "YES";
  40. return 0;
  41. }
  42. for (int i = 1; i <= n-1; i++) {
  43. if (s[i] == '0' && !IsNumber(s[i - 1])) {
  44. cout << "NO";
  45. return 0;
  46. }
  47. }
  48. for (int i = 1; i <= n-2; i++) {
  49. if (s[i] == '1' && !IsNumber(s[i - 1]) && !IsNumber(s[i+1])) {
  50. cout << "NO";
  51. return 0;
  52. }
  53. }
  54. if (s[n - 1] == '1' && !IsNumber(s[n - 2])) {
  55. cout << "NO";
  56. return 0;
  57. }
  58. for (int i = 0; i < n; i++) {
  59. if (IsUpper(s[i])) {
  60. s1.push_back(s[i]);
  61. continue;
  62. }
  63. if (IsLower(s[i])) {
  64. s1.push_back(s[i]);
  65. continue;
  66. }
  67. if (IsNumber(s[i])) {
  68. continue;
  69. }
  70. cout << "NO";
  71. return 0;
  72. }
  73. swap(s1, s);
  74. n = s.size();
  75. s1.clear();
  76. s1.push_back(s[0]);
  77. for (int i = 1; i < n; i++) {
  78. if (IsUpper(s[i])) {
  79. elem.push_back(s1);
  80. s1.clear();
  81. }
  82. s1.push_back(s[i]);
  83. }
  84. if (!s1.empty()) {
  85. elem.push_back(s1);
  86. }
  87.  
  88.  
  89. for (int i = 0; i < elem.size(); i++) {
  90. if (elem[i].size() > 2) {
  91. cout << "NO";
  92. return 0;
  93. }
  94. if (i > 0 && elem[i] == elem[i - 1]) {
  95. cout << "NO";
  96. return 0;
  97. }
  98. }
  99. cout << "YES";
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement