Write a program that enters two integers n and l and generates in alphabetical order all possible "dumb" passwords that consist of the following 5 characters:
- Character 1: digit from 1 to n.
- Character 2: digit from 1 to n.
- Character 3: small letter among the first l letters of the Latin alphabet.
- Character 4: small letter among the first l letters of the Latin alphabet.
- Character 5: digit from 1 to n, bigger than first 2 digits.
The input is read from the console and consists of two integers: n and l within the range [1 … 9], each on a single line.
Print on the console all "dumb" passwords in alphabetical order, separated by space.
|11aa2 11ab2 11ac2 11ad2 11ba2 11bb2 11bc2 11bd2 11ca2 11cb2 11cc2 11cd2 11da2 11db2 11dc2 11dd2||3
|11aa2 11aa3 12aa3 21aa3 22aa3|
|11aa2 11aa3 11ab2 11ab3 11ba2 11ba3 11bb2 11bb3 12aa3 12ab3 12ba3 12bb3 21aa3 21ab3 21ba3 21bb3 22aa3 22ab3 22ba3 22bb3||4
|11aa2 11aa3 11aa4 11ab2 11ab3 11ab4 11ba2 11ba3 11ba4 11bb2 11bb3 11bb4 12aa3 12aa4 12ab3 12ab4 12ba3 12ba4 12bb3 12bb4 13aa4 13ab4 13ba4 13bb4 21aa3 21aa4 21ab3 21ab4 21ba3 21ba4 21bb3 21bb4 22aa3 22aa4 22ab3 22ab4 22ba3 22ba4 22bb3 22bb4 23aa4 23ab4 23ba4 23bb4 31aa4 31ab4 31ba4 31bb4 32aa4 32ab4 32ba4 32bb4 33aa4 33ab4 33ba4 33bb4|
We can split the solution of the problem into 3 parts:
- Reading the input – in the current problem this includes reading two numbers
l, each on a single line.
- Processing the input data – using of nested loops to iterate through every possible symbol for each of the five password symbols.
- Printing the output – printing every "dumb" password that meets the requirements.
For reading of input data we will declare two integer variables
Let's declare and initialize the variables that will store the characters of the password: for the characters of digit type –
d3, and for the letters – of
char type –
l2. To make it easier we will skip explicit specification of the type by replacing it with the keyword
We need to create five
for nested loops, one for each variable. To ensure that the last digit d3 is greater than the first two, we will use the built-in function
Test your solution here: https://judge.softuni.org/Contests/Practice/Index/515#0.
- In C# we can define a
forloop with variable of
- We can read variable of
chartype from the console with the following structure:
- We can convert a Capital char into small one, using a built-in C # function:
- By reading the chars from the console, we can directly convert upper to lowercase letters, by combining the above two lines: