Padovan string , C/C++ Programming

Assignment Help:

write a program that counts the number of occurences of the string in the n-th Padovan string P(n)

program in java

// aakash , suraj , prem sasi kumar kamaraj college
program 1 :

package test.padovanstring;

public class PadovanString {
    public int stringOccurrences(int n, String str){
   
    if(n >= 40)
    return -1;
    if(str.replaceAll("X|Y|Z","").length()>0)
    return -1;
    String res=pad(n);
    return(res.length() - res.replaceAll(str,"").length())/(str.length());
    }
public String pad(int n){
    if(n == 0) return "X";
    if(n == 1) return "Y";
    if(n == 2) return "Z";
    else return pad(n-2) + pad(n-3);
   
}
    public static void main(String []args)
    {
        PadovanString p = new PadovanString();
        System.out.println(p.stringOccurrences(21,"YZ"));
    }
}

 

 

 

Program set 2 :

import java.util.Scanner;

import java.util.ArrayList;

 

public class PadovanSeries

{

    public static void main(String[] arg)

    {

        Scanner read = new Scanner(System.in);

        System.out.println("Enter starting no. : ");

        int start = read.nextInt();

        System.out.println("Enter ending no. : ");

        int end = read.nextInt();

        int[] ans = getSeries(start, end);

        System.out.println("Padovan series : ");

        for (int a : ans)

            System.out.print(a + " ");

    }

 

    public static int[] getSeries(int s, int e)

    {

        ArrayList list = new ArrayList();

        int i, j = 0;

        for (i = s; i <= e; i++, j++)

            list.add(getPadovan(i));

        int[] ans = new int[j];

        for (i = 0; i < j; i++)

            ans[i] = list.get(i);

        return ans;

    }

 

    public static int getPadovan(int p)

    {

        if (p == 0 || p == 1 || p == 2)

            return 1;

        return (getPadovan(p - 2) + getPadovan(p - 3));

    }

}

 

Padova


Related Discussions:- Padovan string

Computer, Is computer an intelligent machine?

Is computer an intelligent machine?

Write a c program to add two complex numbers, #include stdio.h   struct  c...

#include stdio.h   struct  complex   {   float real;   float imag;   };   struct complex complexadd(struct complex,struct  complex);   void main()     {          Date: 26

String, Write a program that takes 3 small letters as input and sort them a...

Write a program that takes 3 small letters as input and sort them according to their ASCII value.

Padovan string, padovan string for natural numbers program in java /...

padovan string for natural numbers program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class Padov

How to write an inline class member function, How to write an inline class ...

How to write an inline class member function In addition to global functions, you may request that non-static member functions of a class be inlined.  The normal method of doin

Flowchart, questiCreate a flowchart that displays the student''''s average ...

questiCreate a flowchart that displays the student''''s average score for three quizzes. + Assume that there are 3 sections each having 5 students + The only valid number to be en

Program to define an array in c, Program to define an array in c: Writ...

Program to define an array in c: Write a program to define an array and print the value of array. void main() { int a[10]={0,11,21,34,44,75,46,57,88,89},i,j,k; clr

Binary options ea for directfx and signalpush, Binary Options EA for Direct...

Binary Options EA for DirectFX and SignalPush Project Description: I want a programmer who will build an EA based on my three types of Binary strategy's using two Indicators.

Lexicographically preceding permutation, Given an integer n and a permutati...

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

Circular linked list assignment, need an expert programmer to finish coding...

need an expert programmer to finish coding the requirements from the assignment withen 4 hrs

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