题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <algorithm> #include<numeric>//accumulate函数在这个库中定义 using namespace std; string mimayanzheng(string str){ int arr[4] ={0}; int num = 0; int len = str.size(); for(int i=0;i<len;i++){ if(isupper(str[i])){ arr[0] = 1; }else if(islower(str[i])){ arr[1] = 1; }else if(isdigit(str[i])){ arr[2] = 1; }else{ arr[3] = 1; } } int again = 0; for(int i = 0;i<=len-6;i++){ //虽然是len-6 但是i在下面还是可以取到len-5 len -4 for(int j = i+3;j<len;j++){ if(str.substr(i,3)==str.substr(j,3)){ again++; } } } if((str.size()>8)&&(again==0)&&(accumulate(arr,arr+4,0)>2)){ return "OK"; }else{ return "NG"; } return 0; } int main(){ string str; while(getline(cin,str)){ cout<<mimayanzheng(str)<<endl; } return 0; }