Official

B - Weak Password Editorial by mechanicalpenciI


それぞれの条件をみたすかを if 文などを用いて判定すればよいです。 \(9\)\(0\) の間の判定は個別に分けても良いですし、 \(10\) で割った余りで見ることもできます。

やや強引な方法としては、弱い暗証番号の候補が \(20\) 個しかないため、すべてと比較して判定する事もできます。

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

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: