Passcode generator


  • 1
    S
    #include <iostream>
    #include <string>
    using namespace std;
    int main() {
        vector<int> a = {0, 0, 0};
        set<string> used;
        auto tostr = [&](int i) -> string{
            return to_string(a[i - 3]) + to_string(a[i - 2]) + to_string(a[i - 1]) + to_string(a[i]);
        };
        bool flag = true;
        while (flag){
            flag = false;
            a.push_back(0);
            for (int i = 0; i <= 9; i++){
                if (tostr(a.size() - 1) == "9000"){
                    if (i == 0) continue;
                }
                if (tostr(a.size() - 1) == "9900"){
                    if (i == 0) continue;
                }
                if (tostr(a.size() - 1) == "9990"){
                    if (i == 0) continue;
                }
                a.back() = i;
                if (used.find(tostr(a.size() - 1)) == used.end()){
                    flag = true;
                    used.insert(tostr(a.size() - 1));
                    break;
                }
            }
        }
        for (int i = 0; i < 3; i++){
            a.push_back(0);
            used.insert(tostr(a.size() - 1));
        }
        cout<<used.size()<<endl;
        std::cout << "Hello World!\n";
    }
    

  • 1

  • 1
    S
    This post is deleted!

  • 1
    S

    what if unsorted?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.