题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream>
using namespace std;
int mul(string s)
{
if(s.size() <= 8){
return -1;
}
for(int i=0;i<s.size();i++){
for(int j=i+1;j<s.size();j++){
if(s.substr(i,3) == s.substr(j,3)){
return -1;
}
}
}
return 0;
}
int is(int a)
{
if(a != 0){
a =1;
}else {
a =0;
}
return a;
}
int kinds(int a,int b,int c,int d)
{
a=is(a);
b=is(b);
c=is(c);
d=is(d);
if(a + b + c +d >= 3){
return 0;
}else{
return -1;
}
return 0;
}
int deal_str(string s)
{
int a=0;
int b=0;
int c=0;
int d=0;
for(auto e : s){
if('0' <= e && e <= '9'){
a++;
}else if('a' <= e && e <= 'z'){
b++;
}else if('A' <= e && e <= 'Z'){
c++;
}else if(e != ' ' && e != '\n'){
d++;
}
}
int ret = kinds(a,b,c,d);
int ret0 = mul(s);
if(ret == 0 && ret0 == 0){
return 0;
}else{
return -1;
}
return 0;
}
int main() {
string s;
while(getline(cin,s)){
int ret = deal_str(s);
if(ret == 0){
cout << "OK" << endl;
}else{
cout << "NG" << endl;
}
}
}
// 64 位输出请用 printf("%lld")
CVTE公司福利 671人发布