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...
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.
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
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.)
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.
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.
How many bit strings of length 8 if i. bit strings start with the bit 1;...
How many bit strings of length 8 if i. bit strings start with the bit 1; ii. bit strings end with the two bits 00; iii. bit strings either start with the bit 1 or end with the bits 00.؟
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT