HackerRank : Week of Code 30 – Melodious password

By | March 15, 2017
Melodious password : Hackerrank

Jeremy and Clara are learning about passwords and created a game to test their “hacking” skills. Jeremy made rules for valid passwords and Clara needs to write a program to generate all possible passwords that meet those rules. Jeremy’s rules are these:

  • a password consists of exactly lowercase English letters.
  • the password is melodious, meaning that consonants can only be next to vowels and vowels can only be next to consonants. Example: bawahaha
  • the password cannot contain the letter (because it’s both a consonant and vowel).
  • the first letter of the password can be either a vowel or consonant.

image

Given the length, , of the password, output all of the possible passwords that meet the conditions above. Your output will be considered correct if and only if it contains all melodious passwords of length .

Input Format

The line of input contains the integer (the length of the password).

Output Format

Print your output strings, one per line. Your output will be considered correct if and only if it contains all melodious passwords of length in any order.

Sample Input 0

1

Sample Output 0

w
t
v
g
l
o
h
i
x
q
j
r
k
p
a
m
d
e
z
c
n
u
b
f
s

Explanation 0

The length of the password is . We can list all letters except for our list of possible passwords.

Solution

package weekOfCode30;

import java.util.Scanner;

public class MelodiousPassword {
	
	public static void main(String[] args) {
		
		Scanner scan= new Scanner(System.in);		
		int n=scan.nextInt();

		int index = 97;
		for(int i=0;i<26;i++)
		{
			char b = (char) index;
			if(index==121)
			{}
			else
			System.out.println(b);		
			index++;
		}
		
	}
}