Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int N = 2e5;
- string s, s1;
- vector<string> elem;
- bool IsUpper(char a) {
- return a >= 'A' && a <= 'Z';
- }
- bool IsLower(char a) {
- return a >= 'a' && a <= 'z';
- }
- bool IsNumber(char a) {
- return a >= '0' && a <= '9';
- }
- int main()
- {
- cin >> s;
- int n = s.size();
- if (IsNumber(s[0])) {
- cout << "NO";
- return 0;
- }
- if (IsLower(s[0])) {
- cout << "NO";
- return 0;
- }
- if (s.size() == 1) {
- cout << "YES";
- return 0;
- }
- for (int i = 1; i <= n-1; i++) {
- if (s[i] == '0' && !IsNumber(s[i - 1])) {
- cout << "NO";
- return 0;
- }
- }
- for (int i = 1; i <= n-2; i++) {
- if (s[i] == '1' && !IsNumber(s[i - 1]) && !IsNumber(s[i+1])) {
- cout << "NO";
- return 0;
- }
- }
- if (s[n - 1] == '1' && !IsNumber(s[n - 2])) {
- cout << "NO";
- return 0;
- }
- for (int i = 0; i < n; i++) {
- if (IsUpper(s[i])) {
- s1.push_back(s[i]);
- continue;
- }
- if (IsLower(s[i])) {
- s1.push_back(s[i]);
- continue;
- }
- if (IsNumber(s[i])) {
- continue;
- }
- cout << "NO";
- return 0;
- }
- swap(s1, s);
- n = s.size();
- s1.clear();
- s1.push_back(s[0]);
- for (int i = 1; i < n; i++) {
- if (IsUpper(s[i])) {
- elem.push_back(s1);
- s1.clear();
- }
- s1.push_back(s[i]);
- }
- if (!s1.empty()) {
- elem.push_back(s1);
- }
- for (int i = 0; i < elem.size(); i++) {
- if (elem[i].size() > 2) {
- cout << "NO";
- return 0;
- }
- if (i > 0 && elem[i] == elem[i - 1]) {
- cout << "NO";
- return 0;
- }
- }
- cout << "YES";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement