Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Increasing Passwords.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- void waitLine()
- {
- cin.clear();
- cin.ignore(255, '\n');
- cin.get();
- }
- //Logic for increasing a base 36 number
- void incrChar(string &Password, int curChar)
- {
- curChar--;
- if (Password[curChar] == 32)
- {
- Password[curChar] = char(65);
- }
- else if (((Password[curChar] > 64) && (Password[curChar] < 90)) || ((Password[curChar] > 47) && (Password[curChar] < 57)))
- {
- Password[curChar]++;
- }
- else if (Password[curChar] == 90)
- {
- Password[curChar] = 48;
- }
- else
- {
- Password[curChar] = 'A';
- incrChar(Password, curChar);
- }
- }
- //Check for alphebetisation and repeats
- bool isValid(string Password)
- {
- bool r = true;
- for (int i=0; i<36; i++)
- {
- if (!(Password[i]==char(32)))
- {
- for (int j=i+1; j<36; j++)
- {
- if (Password[i]>char(64))
- {
- if (Password[j]<=Password[i] && Password[j]>64)
- {
- r = false;
- }
- }
- else
- {
- if (Password[j]<=Password[i] || Password[j]>64)
- {
- r = false;
- }
- }
- }
- }
- }
- return r;
- }
- string nthPassword(int n)
- {
- string Password = " ";
- do
- {
- incrChar(Password, 36);
- if (isValid(Password))
- {
- n--;
- }
- } while (n>0);
- return Password;
- }
- int main()
- {
- int n;
- cin >> n;
- cout << nthPassword(n);
- waitLine();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement