1. 程式人生 > 其它 >HJ20 密碼驗證合格程式

HJ20 密碼驗證合格程式

#include<bits/stdc++.h>
using namespace std;
string Password(string str){
    int len  = str.size();
    int a[4] = {0};
    int count = 0;
    int num = 0;//重複子串對數 
    for(int i = 0;i<len;i++){
        if(str[i] >= 'A'&&str[i] <= 'Z') a[0] = 1;    
        else if(str[i] >= 'a'&&str[i] <= '
z') a[1] = 1; else if(str[i] >= '0'&&str[i] <= '9') a[2] = 1; else a[3] =1; } for(int i = 0;i<4;i++){ if(a[i] == 1) count++; } for(int i =0;i <= len-6;i++ ){ //兩個迴圈相當於有兩個框第一個框從0開始大小為3, //第二個框 從3開始大小為3 第二個框若不同則右移一格在比, //若到頭,則第一個框右移一格同時第二個框從4開始
for(int j =i+3;j<=len-3;j++){ if(str[i] == str[j]&&str[i+1]&&str[i+2] == str[j+2]) { cout<<num<<" "; num++; } if(num != 0) break; } if(num!=0) break; } cout<<len<<"
*"<<count<<"*"<<num<<endl; if(len>8&&count>2&&num ==0) return "ok"; else if(len< 8||count<2||num>0) return "NG"; } int main(){ string str; while(getline(cin,str)){ cout<<Password(str)<<endl; } return 0; }