zoukankan      html  css  js  c++  java
  • 华为机试题 密码验证合格程序

    简介

    简单

    code

    #include <iostream>
    #include <string>
    #include <set>
    #include <algorithm>
    using namespace std;
    
    int main() {
        string str;
        set<string> s;
        while(cin >> str) {
            if(str.size() <= 8) {
                cout << "NG
    ";
                continue;
            }
            int check = 0x00;
            for(int i=0; i<str.size(); i++){
                if(str[i] >= '0' && str[i] <='9') {
                    check |= 1;
                }
                else if(str[i] >='a' && str[i] <= 'z') {
                    check |= 2;
                }
                else if(str[i] >='A' && str[i] <= 'Z') {
                    check |= 4;
                }
                else {
                    check |= 8;
                } 
            }
            int numCheck = 0;
            //cout << "ccc " << check << endl;
            //cout << (check & 1) << " " << (check & 2) << " " <<  (check & 4) << " " << (check & 8) << std::endl;
            numCheck += (check & 1) > 0 ? 1 : 0;
            numCheck += (check & 2) > 0 ? 1 : 0;
            numCheck += (check & 4) > 0 ? 1 : 0;
            numCheck += (check & 8) > 0 ? 1 : 0;
            check = false;
            for(int i=0; i<str.size()-2; i++){
                for(int j = i+3; j<str.size()-2; j++){
                    if(str.substr(i,3) == str.substr(j, 3)){
                        check = true;
                    }
                }
            }
            // cout << numCheck << " " << check << endl;
            if(numCheck >= 3 && !check ){
                cout << "OK
    ";
                
            }else{
                cout << "NG
    ";
            }
        }
        return 0;
    }
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    剑指offer【面试题10 :矩形覆盖】
    剑指offer【面试题3 :二维数组中的查找】
    GStreamer Tutorials
    CMake Tutorial
    python
    python
    python-线程、进程、协程
    python-类的继承
    python-操作缓存
    python-线程池
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/14929802.html
Copyright © 2011-2022 走看看