Question

In: Computer Science

1. Write a Post system that defines the set of binary strings of odd length that...

1. Write a Post system that defines the set of binary strings of odd length that have a “x” as the middle
character and "x" is a string

Solutions

Expert Solution

#include<iostream>
using namespace std;

// Function to print given string in cross pattern
// Length of string must be odd
void printPattern(string str)
{
    int len = str.length();

    // i goes from 0 to len and j goes from len-1 to 0
    for (int i=0,j=len-1; i<=len,j>=0; i++,j--)
    {
        // To print the upper part. This loop runs
        // til middle point of string (i and j become
        // same
        if (i<j)
        {
            // Print i spaces
            for (int x=0; x<i; x++)
                cout << " ";

            // Print i'th character
            cout << str[i];

            // Print j-i-1 spaces
            for (int x=0; x<j-i-1; x++)
                cout << " ";

            // Print j'th character
            cout << str[j] << endl;
        }

        // To print center point
        if (i==j)
        {
            // Print i spaces
            for (int x=0; x<i; x++)
                cout << " ";

            // Print middle character
            cout << str[i] << endl;
        }

        // To print lower part
        else if (i>j)
        {
            // Print j spances
            for (int x = j-1; x>=0; x--)
                cout << " ";

            // Print j'th character
            cout << str[j];

            // Print i-j-1 spaces
            for (int x=0; x<i-j-1; x++)
                cout << " ";

            // Print i'h character
            cout << str[i] << endl;
        }
    }
}

// Driver program
int main()
{
    printPattern("010101 X 101010");
    return 0;
}


Related Solutions

Recall that the set {0,1}∗ is the set of all finite-length binary strings. Let f:{0,1}∗→{0,1}∗ to...
Recall that the set {0,1}∗ is the set of all finite-length binary strings. Let f:{0,1}∗→{0,1}∗ to be f(x1x2…xk)=x2x3…xkx1. That is, f takes the first bit of a string x and moves it to the end of x, so for example a string 100becomes 001; if |x|≤1, then f(x)=x Also, suppose that g:{0,1}∗→{0,1}∗ is a function such that g(x1…xk)=0x1…xk (that is, gg puts an extra 0 in front of the given string, so for example g(100)=0100. Everywhere in this question we...
Python.Python.Python. Write a functional program over the automata that accepts odd length binary digits and rejects...
Python.Python.Python. Write a functional program over the automata that accepts odd length binary digits and rejects those that are not. It must include a function called q0 ,q1, accept and reject(). CANNOT USE STRING. OR LENTH. 101 accepted (3 binary digits) 10610 rejected (the number 6 is not a binary number) 101111 rejected (6 digit binary number) 11111 accepted (5 binary digits)
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number...
Give regular expressions for (c) C indentifiers (d) Binary strings consisting of either an odd number of 1s or an odd number of 0s
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Design an efficient algorithm to compute the number of binary strings with length n that satisfy...
Design an efficient algorithm to compute the number of binary strings with length n that satisfy 1 the regular expression ((0 + 11 + 101)∗ (1101))∗ .
Find a recurrence relation for the number of binary strings of length n which do not...
Find a recurrence relation for the number of binary strings of length n which do not contain the substring 010
Use inclusion-exclusion to find the number of binary strings of length 5 that have at least...
Use inclusion-exclusion to find the number of binary strings of length 5 that have at least one of the following characteristics: start with a 1, end with a 0, or contain exactly two
Construct a quantum protocol that produces equally likely binary strings of length six. (A quantum protocol...
Construct a quantum protocol that produces equally likely binary strings of length six. (A quantum protocol is a classical algorithm which uses at least one quantum computation. For example, an algorithm which uses Shor’s algorithm to factor a natural number as part of an attack to decrypt a code.)
Set A = {1, 2, 3, 4}, write a binary relation R on A that is...
Set A = {1, 2, 3, 4}, write a binary relation R on A that is reflexive, symmetric and transitive, with (1, 2),(3, 2) ∈ R.
Suppose that you pick a bit string from the set of all bit strings of length...
Suppose that you pick a bit string from the set of all bit strings of length ten. Find the probability that the bit string has exactly two 1s; the bit string begins and ends with 0; the bit string has the sum of its digits equal to seven; the bit string has more 0s than 1s; the bit string has exactly two 1s, given that the string begins with a 1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT