Official

B - Weak Password Editorial by en_translator


Check if each condition is satisfied with conditional branches like if statements. One can check the pairs of \(9\) and \(0\) separately, or by exploiting the remainder by \(10\).

Alternatively, you may take a brute-force approach of comparing it with all the possible weak password, since there are only \(20\) candidates of them.

Sample code in C++:

#include <bits/stdc++.h>
using namespace std;

int main(void) {
	char a[5];
	for (int i = 0; i < 5; i++)a[i] = 0;
	cin >> a;
	bool same = true;
	bool step = true;
	for (int i = 0; i < 3; i++) {
		if (a[i] != a[i + 1])same = false;
		if (((a[i] + 1) % 10) != (a[i + 1] % 10))step = false;
	}
	if (same || step)cout << "Weak" << endl;
	else cout << "Strong" << endl;
	return 0;
}

Sample code in Python:

a = input()
same,step = True,True
for i in range(3):
    if a[i]!=a[i+1]:
        same=False
    if (int(a[i])+1)%10!=int(a[i+1]):
        step=False
if(same or step):
    print("Weak")
else:
    print("Strong")

posted:
last update: