Strong Password
National Olympiad — Municipal round (2026 season)
Submission name: password.cpp
Problem summary
Check a six-character password. It must contain a lowercase Latin letter, an uppercase Latin letter and a digit, and adjacent characters must never be equal.
Input
One string of exactly six letters or digits.
Output
YES if every condition holds; otherwise NO.
Constraints
Exactly 6 characters, each in a–z, A–Z or 0–9.
Worked example
An independently prepared example for this explanation.
Input
aB3cD4
Output
YES
Solution analysis
- Maintain three flags for the required character types and a fourth flag for whether any adjacent equal pair has appeared.
- Inspect each character once. Explicit ASCII range checks distinguish lowercase letters, uppercase letters and digits. For positions after the first, compare with the previous character.
- aB3cD4 contains all three types and has no repeated adjacent characters, so it is accepted. aB33cD fails even though all three types are present. A repeated letter elsewhere, such as the two a characters in aB3aC4, is allowed.
Why it works
Each character sets exactly the relevant type flag. Comparing every pair of consecutive positions detects every forbidden adjacency. The final conjunction is therefore exactly the definition of a strong password.
Watch out. Do not reject every repeated character: only consecutive equal ones are forbidden. Avoid reading password[i−1] when i = 0. Letter case matters.
Commented C++17 solution
An independently written complete program with standard headers.
#include<iostream>
#include<string>
using namespace std;
int main() {
string password;
cin >> password;
bool hasLowercase = false;
bool hasUppercase = false;
bool hasDigit = false;
bool hasEqualNeighbors = false;
for (int i = 0; i < static_cast<int>(password.size()); i++) {
char symbol = password[i];
hasLowercase = hasLowercase || (symbol >= 'a' && symbol <= 'z');
hasUppercase = hasUppercase || (symbol >= 'A' && symbol <= 'Z');
hasDigit = hasDigit || (symbol >= '0' && symbol <= '9');
if (i > 0 && symbol == password[i - 1]) {
hasEqualNeighbors = true;
}
}
if (hasLowercase && hasUppercase && hasDigit && !hasEqualNeighbors) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}