Given a string S that contains lowercase English letters representing different types of
candies. A substring of a string S is a string Ssub that occurs in S. For example, "twix" is a
candy name which is the substring of "twtwixtwixnerdstwixnerds". Each candy costs 1 unit.
You can pick some consecutive candies such that you can create a palindrome of length L by
using some or all picked candies while the number of all possible cases K (all possible
palindromes) is given. The main goal is to find the minimum cost to create a palindrome of
length L. For example,
S= twtwixtwixnerdstwixnerds
L=8
K=4
P= twixtwix
Your task is to identify and define all possible inputs and outputs of a such given problem.
Use Java language.
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;
// Program to find the palindrome name of the candies in a
String
//string: twtwixtwixnerdstwixnerds
public class Palindrome {
// Function will return palindrome
// sub-string to be added
private static void searchPalindromeCandies(String
str,int L) {
String s1 =
"",s2="";
int N = str.length(),
count = 0;
// to hold the pallindrome
strings
Set<String>
palindromeArray = new HashSet<String>();
System.out.println("Given string : " + str);
System.out.println("\n******** Substring palindrome
*******");
//calculate the mid of the
substring
int mid=(L+1)/2;
int minCost=0;
boolean
isFirstPallindromGot=false;
for (int j = 0; j <= N-mid; j++) {
s1 = str.substring(j, j+mid);
s2=s1+s1;
//count the min cost to find the first
palindrome
if(!isFirstPallindromGot)
minCost++;
if (str.contains(s2)) {
palindromeArray.add(s2);
isFirstPallindromGot=true;
}
}
//print all palindrome
strings
System.out.println(palindromeArray);
for (String s :
palindromeArray)
System.out.println(s + " - sub-string is a palindrome.");
System.out.println("The
no.of palindrome are: "+ palindromeArray.size());
System.out.println("The Min. Cost :
"+minCost);
}
// Driver program
public static void main(String[] args)
{
Scanner sc=new
Scanner(System.in);
//user string input
System.out.print("Enter Any String:
");
String str = sc.next();
//Length of Palindrome (two times
of candies name)
System.out.print("Enter Length Of
Pallindrome: ");
int L=sc.nextInt();
searchPalindromeCandies(str,L);
}
}

Given a string S that contains lowercase English letters representing different types of candies. A substring...
Palindromes A palindrome is a nonempty string over some alphabet that reads the same forward and backward. Examples of palindromes are all strings of length 1, civic, racecar, noon, and aibohphobia (fear of palindromes). You may assume that in the problems below, an input string is given as an array of characters. For example, input string noon is given as an array s[L.4], where s[1] = n, s[2] = o, s[3] = o, and s[4] = n. (a) (15 pts)...
Programming language: Java m: substring length n: input strings d: Hamming distance (mismatch) I: Number of letters in Sample input string (s1, s2, s3) Strings consists of: A, C, G, and T Example outputs: Generate all possible possibilities of length m(4) using the values A, C, G, and T. EX possibilites: {A,A,A,A A,A,A,C.... G,G,G,G} and find all the possible combinations that have the same sequence with a hamming distance of 1 (only 1 difference) Given n input strings of length...
Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that occurs as consecutive characters (not just letters, but any characters) in s. so longestSubpalindrome("ab-4-be!!!") returns "b-4-b".If there is a tie, return the lexicographically larger value -- in Python, a string s1 is lexicographically greater than a string s2 if (s1 > s2). So: longestSubpalindrome("abcbce") returns "cbc", since ("cbc" > "bcb"). Note that unlike the previous functions, this function is case-sensitive (so "A" is not...
Given a str s, create a new str variable out that contains all of the letters in s that come after "j" in the alphabet, in their original order (hint: use the > operator). For example, if s is "hello", out should contain "llo". If s is "onmlkjih", out should contain "onmlk". If s is "abc", out should contain "" (i.e., an empty string). In Python
Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...
A CERTAIN program to user's password containing rules such as
least n length, one uppercase, lowercase, one digit and white space
is given as the code down below. So, simiiar to those rules, I need
the code for the following questions post in pictures such as no
more three consecutive letters of English alphabets, password
should not contain User name and so on.
//GOAL: To learn how to create that make strong passwords
//Purpose: 1)To learn some rules that makes...
You will be given several strings full of different keyboard
characters, some of which are letters of the alphabet.
Write a java program that creates a binary tree that uses
only the alphabetical characters (a-z, A-Z) as the value within the
leaf nodes using recursion and preorder traversal. All
other values within the tree (either the root node or internal
nodes) will be null. You may create any methods you see fit, so
long as the final binary tree is...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...
Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers (the "backwards" cipher, the Rail Fence cipher, and the Column Transposition cipher) where the ciphertext is created via an altered presentation of the plaintext. The algorithm for each is detailed in the function descriptions in this section. (13 points) def backwards_cipher(plaintext, key): • Parameter(s): plaintext ----- a string; the message to be encrypted key ----- an integer; the number to control this cipher •...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...