Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Increasing Passwords II.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <array>
- using namespace std;
- void waitLine()
- {
- cin.clear();
- cin.ignore(255, '\n');
- cin.get();
- }
- bool scanRight (int Password[], int curChar)
- {
- bool success = true;
- if (curChar<35)
- {
- if (curChar+1>=Password[curChar]) //Checks for viability of this start of a password.
- {
- if (Password[curChar+1]<=Password[curChar])
- {
- Password[curChar+1]=Password[curChar]+1;
- success = scanRight(Password,curChar+1);
- }
- }
- else
- {
- success = false;
- }
- }
- return success;
- }
- void incrChar (int Password[], int curChar)
- {
- if (Password[curChar]<36)
- {
- Password[curChar]++;
- bool valid = true;
- valid = scanRight(Password, curChar);
- //If this value of Password[curChar] isn't allowed, increase it again.
- if (!valid)
- {
- incrChar(Password, curChar);
- }
- }
- else
- {
- for (int i=curChar; i<37; i++)
- {
- Password[i]=1;
- }
- incrChar(Password, curChar-1);
- }
- }
- string makeString (int Password[])
- {
- string strPassword;
- for (int i=0; i<36; i++)
- {
- if (Password[i]>26)
- {
- strPassword = strPassword + char(Password[i]+21);
- }
- else if (Password[i]>0)
- {
- strPassword = strPassword + char(Password[i]+64);
- }
- }
- return strPassword;
- }
- string nthPassword(int n)
- {
- //Declare and initialise our password array.
- int Password[36];
- for (int i=0; i<36; i++)
- {
- Password[i] = 0;
- }
- //Find the nth by working through all values of the password.
- for (; n>0; n--)
- {
- incrChar(Password, 35);
- }
- return makeString(Password);
- }
- //Find correct st, nd, rd, or th.
- string suffix (int n)
- {
- string thisSuffix;
- switch (n%10)
- {
- case 1:
- thisSuffix = "st";
- break;
- case 2:
- thisSuffix = "nd";
- break;
- case 3:
- thisSuffix = "rd";
- break;
- default:
- thisSuffix = "th";
- }
- return thisSuffix;
- }
- int main()
- {
- //Read in our value
- int n;
- cin >> n;
- //And output that password.
- cout << "The " << n << suffix(n) << " password is: " << nthPassword(n);
- //Wait for user input.
- waitLine();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement