cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2026 · EasyString checks

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

  1. Maintain three flags for the required character types and a fourth flag for whether any adjacent equal pair has appeared.
  2. 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.
  3. 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.

Complexity: O(L) time and O(L) space for the input string, with O(1) working space. Here L = 6, so both are bounded constants.

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";
    }
}

Source: Arena Olimpiici ↗