Padovan string, Programming Languages

Assignment Help:

Padovan String

Problem Description


A Padovan string P(n) for a natural number n is defined as:

P(0) = 'X'

P(1) = 'Y'

P(2) = 'Z'

P(n) = P(n-2) + P(n-3), n>2
where + denotes string concatenation.
For a string of the characters 'X' , 'Y' and 'Z' only, and given value of n, write a program that counts the number of occurrences of the string in the n-th Padovan string P(n).


An example is given below.

For n = 6 and the string ZY, the program should count the occurrences of ZY in P(6).

P(0) = 'X'

P(1) = 'Y'

P(2) = 'Z'

P(n) = P(n-2) + P(n-3), n>2


P(3) = P(1)+P(0)

P(3) = YX


P(4) = P(2)+P(1)

P(4) = ZY


P(5) = P(3)+P(2)

P(5) = YXZ


P(6) = P(4)+P(3)

P(6) = ZYYX

So, the number of occurrences of the string ZY in P(6) is 1.

Instruction to work with Open PBT Client:

  1. Specify the work directory path in the 'Work directory Path' field. The path should correspond to your solution Work directory.
  2. Download the support files by clicking the Get Dev Files.
  3. You will find the problem directories containing:
    • problem.h file
    • problem.c file

in your project directory.

  1. Code the solution in .c file inside the problem directory
  2. All required files will be downloaded to your work directory. Creating additional files is strongly discouraged.

Step 1:

In your Solution File:

  • Implement your logic in function int stringOccurrences(int n, char* str)
  • int   n :n is an integer represents n(th) for which full main string has to formed, from which occurrence of string str has to be found.
  • char*    str :str is a string represents sub string whose occurrence has to be found in the main string.
  • You can create more functions if required, but those functions should be in the same file.

 

Step 2:

In your solution keep in mind the following constraints:.

  1. In this problem you have to write a program that counts the number of occurrences of the string in the n-th Padovan string P(n).
  2. Padovan formula is P(n) = P(n-2) + P(n-3) where n>2 and n is the integer.
  3. In the above Padovan formula + sign means string concatenation.
  4. For the Padovan formula value of P(0),P(1) and P(2) is given. You have to use those value only.
  5. n should not be greater than 40 otherwise return -1
  6. string str should be consist of only X,Y and Z in upper case otherwise return -1

The Prototype of the function is

int stringOccurrences(int n, char* str)
This function takes following arguments.

  • n is the value for which full main string has to formed, from which occurrence of string str has to be found.
  • str represents sub string whose occurrence has to be found in the main string.
  • This function returns a number of occurrence of string str in the main string.

The constraints are:

  1. n should not be greater than 40 otherwise return -1
  2. string str should be consist of only X,Y and Z in upper case otherwise return -1

Example 1

Input


int n = 6
string str = ZY

Output


1

Explanation : This question is explained in problem description.

Example 2

Input


int n = 6
String str = ZYmm

Output


-1

Explanation :
String str is containing character other than X, Z and Y.

Example 3

Input


int n = 8
String str = XZ

Output


1

For C solutions

Header File

:

padovanstring.h

Function Name

:

int stringOccurrences(int n, char* str)

File Name

:

padovanstring.c

For C++ solutions

Header File

:

padovanstring.h

Class Name

:

PadovanString

Function Name

:

int stringOccurrences(int n, char* str)

File Name

:

padovanstring.c

General Instructions

    *

The file / class names, functions, method signatures, header files are to be used as mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.

    *

For C solutions, change the value of "C_OR_CPP" macro in header file as 1 and for C++ solutions change the value as 2.

    *

In case of iostream.h specify as iostream only.

    *

Command line options for the main() function are not supported currently.


Related Discussions:- Padovan string

Help with c assignment, You will design and implement a program that will •...

You will design and implement a program that will • analyse the various characteristics of a maze, represented by a particular coding of its basic con- stituents into numbers store

Write a program that draws the initials j, Write a program that draws the i...

Write a program that draws the initials J G P on the form similar to that shown in Fig J 1 (using straight lines and curve semicircles). The figure can not have corners. All ends a

Java virtual machine, Expertsmind.com is expert in java assignment help ...

Expertsmind.com is expert in java assignment help JAVA Virtual Machine A Java exclusive device or java virtual machine (JVM) is an exclusive device able of undertaking Jav

Vb, sir can you help me visual basic 6.0 project solution

sir can you help me visual basic 6.0 project solution

Script shell to display lines of a file in reverse order, Normal 0 ...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Loops, I have doubt in this section .do-while loop.could you able to clear ...

I have doubt in this section .do-while loop.could you able to clear it for me.

Matlab, i have a=[0 1 1 2 2 3 6 7 0 4 ] i want to delent elemet but keep it...

i have a=[0 1 1 2 2 3 6 7 0 4 ] i want to delent elemet but keep its position i.e a(4)=[] it gives me 0 1 1 2 3 6 7 0 4 but i need 0 1 1 [] 2 3 6 7 0 4

Differentiate between high level and low level languages, The languages use...

The languages used in the module are of a type known as high-level languages. There is another set of languages known as low-level languages. (a) Differentiate between high-leve

Expressions and truth tables, Create a logical expression that corresponds ...

Create a logical expression that corresponds to the following statement: If you like talking about computers or playing video games at LAN parties, and you want to meet others w

Extensive programming platform .net, Extensive programming platform .NET ...

Extensive programming platform .NET It is a new, simple, and comprehensive selection foundation. It is not a selection terminology, but it can handle several selection dialects.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd