4. Assignment 9
WAP to generate consecutive NRPS of length ‘n’ using ‘k’
distinct character
5. Assignment 9
WAP to generate consecutive NRPS of length ‘n’ using ‘k’
distinct character
Input:
6. Assignment 9
WAP to generate consecutive NRPS of length ‘n’ using ‘k’
distinct character
Input: Read Positive integers - number of characters ‘k’,
length of the string ‘n’ and ‘k’ distinct characters.
7. Assignment 9
WAP to generate consecutive NRPS of length ‘n’ using ‘k’
distinct character
Input: Read Positive integers - number of characters ‘k’,
length of the string ‘n’ and ‘k’ distinct characters.
Output:
8. Assignment 9
WAP to generate consecutive NRPS of length ‘n’ using ‘k’
distinct character
Input: Read Positive integers - number of characters ‘k’,
length of the string ‘n’ and ‘k’ distinct characters.
Output: Print NRPS.
11. Assignment 9
What is NRPS?
NRPS means Non-Repetitive Pattern String.
Example: abcdabdc -> This string is formed using 4 distinct
characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
The pattern should not be repeated consecutively.
13. Assignment 9
How will you check the string is NRPS or not?
Example: abcdabdc -> This string is formed using 4 distinct
characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
14. Assignment 9
How will you check the string is NRPS or not?
Example: abcdabdc -> This string is formed using 4 distinct
characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
a b c d a b d c 0
NRPS
15. Assignment 9
How will you check the string is NRPS or not?
Example: abcdabdc -> This string is formed using 4 distinct
characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
a b c d a b d c 0
NRPS
First pattern is formed
using the characters a,
b, c and d in order.
16. Assignment 9
How will you check the string is NRPS or not?
Example: abcdabdc -> This string is formed using 4 distinct
characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
a b c d a b d c 0
NRPS
Next pattern is formed
by swapping some
characters. The
pattern should not be
same as previous
pattern.
17. Assignment 9
How will you check the string is NRPS or not?
Step 1: Make use of count variable. Initial value of count is 0.
count = 0.
a b c d a b d c 0
NRPS
18. Assignment 9
How will you check the string is NRPS or not?
Step 2: Start comparing the elements of first pattern and
second pattern using their indices.
a b c d a b d c 0
NRPS
19. Assignment 9
How will you check the string is NRPS or not?
Step 2: Start from ‘a’ from abcd and ‘a’ from abdc.
If, both are same, increment count by 1
a b c d a b d c 0
NRPS
count = 1
20. Assignment 9
How will you check the string is NRPS or not?
Step 2: Then ‘b’ from abcd and ‘b’ from abdc.
If, both are same, increment count by 1
a b c d a b d c 0
NRPS
count = 2
21. Assignment 9
How will you check the string is NRPS or not?
Step 2: Then ‘c’ from abcd and ‘d’ from abdc.
If, both are same, increment count by 1
If not, reset the count value to 0.
a b c d a b d c 0
NRPS
count = 0
22. Assignment 9
How will you check the string is NRPS or not?
Step 2: Then ‘d’ from abcd and ‘c’ from abdc.
If, both are same, increment count by 1
If not, reset the count value to 0.
a b c d a b d c 0
NRPS
count = 0
23. Assignment 9
How will you check the string is NRPS or not?
Step 3: Check the count value.
• If the count value is 0, then the string is NRPS.
• If the count value is other then 0, then the string is not NRPS.
a b c d a b d c 0
NRPS
count = 0
24. Assignment 9
How will you check the string is NRPS or not?
Step 3: Check the count value.
• If the count value is 0, then the string is NRPS.
• If the count value is other then 0, then the string is not NRPS.
• Here, the count value is 0, so, abcdabdc is NRPS.
a b c d a b d c 0
NRPS
count = 0
26. Assignment 9
How to create a NRPS?
Read how many distinct characters(k) are required to create
NRPS from user. Assume ‘k’ = 3.
Read 3 distinct characters from user i.e., ‘a’, ‘b’ and ‘c’.
Read the length(n) of the string to be formed using ‘k’ distinct
characters. n = 6.
27. Assignment 9
How to create a NRPS?
k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.
Step 1: Create the first pattern of characters in order.
a b c
NRPS
28. Assignment 9
How to create a NRPS?
k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.
Step2: Start creating the next pattern starting from index 1.
a b c b
NRPS
29. Assignment 9
How to create a NRPS?
k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.
Step2: Next index 2 can be copied to index 4.
a b c b c
NRPS
30. Assignment 9
How to create a NRPS?
k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.
Step2: When you reach end of the first pattern, start from the
beginning again.
a b c b c a
NRPS
31. Assignment 9
How to create a NRPS?
k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.
a b c b c a 0
NRPS
32. Assignment 9
How to create a NRPS?
Read how many distinct characters(k) are required to create
NRPS from user. Assume ‘k’ = 3.
Read 3 distinct characters from user i.e., ‘a’, ‘b’ and ‘c’.
Read the length(n) of the string to be formed using ‘k’ distinct
characters. n = 9.
33. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step 1: Create the first pattern of characters in order.
a b c
NRPS
34. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step2: Start creating the next pattern starting from index 1.
NRPS a b c b
35. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step2: Next index 2 can be copied to index 4.
NRPS a b c b c
36. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step2: When you reach end of the first pattern, start from the
beginning again.
NRPS a b c b c a
37. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step1: Repeat the process to create next pattern till length ‘n’.
NRPS a b c b c a c
38. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step1: Repeat the process to create next pattern till length ‘n’.
NRPS a b c b c a c a
39. Assignment 9
How to create a NRPS?
k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.
Step1: Repeat the process to create next pattern till length ‘n’.
NRPS a b c b c a c a b
40. Assignment 9
How to create a NRPS?
k = 3, n = 8 and characters are ‘a’, ‘b’ and ‘c’.
NRPS a b c b c a c a b 0