题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
other_symbil = '~!@#$%^&*()_+<>/|[]{}\'; try while 1 line = input('', 's'); line_char = char(line); %% 要求1 label_1 = find(length(line_char) > 8); %% 要求2 dig_la =0;upper_zimu=0;lower_zimu=0; dig_la = length(find(sum(isstrprop(line_char, 'digit')) > 0)); upper_zimu = length(find(sum(isstrprop(line_char,'upper')) > 0)); lower_zimu = length(find(sum(isstrprop(line_char,'lower')) > 0)); other_sy = 0; for ii = 1 : length(line_char) p_1 = strfind(other_symbil,line_char(ii)); if isempty(p_1) else other_sy = 1; continue; end end la_2 = (dig_la + upper_zimu + lower_zimu + other_sy) >= 3; p_3 = 0; %%要求3-子串 for ii = 1:length(line_char)-3 line_char_now = line_char(ii:ii+2); for jj = (ii + 1) : length(line_char)-2 lab_3 = strcmp(line_char_now,line_char(jj:jj+2)); if lab_3 == 0 else p_3 = 1; continue; end end if p_3 == 1 continue; end end %%% 判断 if (label_1 == 1) && (la_2 == 1) && (p_3 == 0) printf("OK \n"); else printf("NG \n"); end end catch end