Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9506576

Have any Question?


Related Questions in Programming Language

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As