Suppose you are given a string str and two positions i and j, where i comes before j. The following pseudocode describes how to swap two letters in a word.
We are given a string str and two positions i and j. (i comes before j)
Set first to the substring from the start of the string to the last position before i.
Set middle to the substring from positions i + 1 to j - 1.
Set last to the substring from position j + 1 to the end of the string.
Concatenate the following five strings: first, the string containing just the character at position j, middle, the string containing just the character at position i, and last.
Check this pseudocode, using the string "Gateway" and positions 2 and 4. Draw a diagram of the string that is being computed, similar to Figure 5.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Python (3rd Edition)
Modern Database Management
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (7th Edition)
- A string is a palindrome if it reads the same from front to back as it does from back to front (e.g. "kayak", "rotator" and "noon" are palindromes). When determining whether an alphanumeric string is a palindrome, we often ignore spaces, punctuation and case in the string (e.g. "A man, a plan, a canal --Panama!" is also considered a palindrome). Write a complete C program to read a string, echo it to the screen, determine whether it is a palindrome, and write a message indicating whether it is or isn't. Your main function should prompt for the string, read the string, print it, call the clean function (to remove all spaces, punctuation, and turn uppercase letters into lowercase letters), print the new string, then call the reverse function (to place the characters into reverse order) and print the new string resulting. In the final step, you will compare the result of the reverse function with the original string and print a message if the string is a palindrome or not. The clean…arrow_forwardIn C Languagearrow_forwardQ1__;. A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise. Example 1: Input: s = "A man, a plan, a canal: Panama" Output: true Explanation: "amanaplanacanalpanama" is a palindrome. Example 2: Input: s = "race a car" Output: false Explanation: "raceacar" is not a palindrome..arrow_forward
- Write a code that determines if a string is a palindrome (can be read forward and backward with the same meaning); e.g. "civic", “elle", “madam" 66 22arrow_forwardIn C Languagearrow_forwardDetermine whether a string is a palindrome A palindrome is a string of characters that reads the same from right to left as it does from left to right, regardless of punctuation and spaces. Some famous English palindromes include the following “Madam, I’m Adam”, and “Never odd or even”. Of course, a simpler example would be the world “radar”.The specifications for this assignment are: Write and test a non-recursive solution in Java that determines whether a string is a palindrome •Your program should consist of at least two methods: (1) the main method (2) the method which performs the task of determining whether the specified string is a palindrome. You should name this method isPalindrome. You should name the class that contains your “main” method and the isPalindrome method FindPalindrome. •You must use a Stack and a Queue in your solution:Make sure to Write your own Stack and Queue based on the Vector in the Java API and use those in your solution. You should name those classes…arrow_forward
- Given a string on one line and an integer number on a second line, add a copy of the last number of characters of the string to the string's end. Then, output the result. Ex: If the input is: Fuzzy bear 4 the output is: Fuzzy bearbear Note: Using a pre-defined string function, the solution can be just one line of code. #include <iostream>#include <string>using namespace std; int main() { string strVar; int substrLen; getline(cin, strVar); cin >> substrLen; /* Your code goes here */ cout << strVar << endl; return 0;}arrow_forwardTake input a string s from the user and print the number of characters less than 's' in the string. String may contain any character. Programming Language- Javaarrow_forwardlanguage using - Javaarrow_forward
- A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes:warts n strawradarAble was I ere I saw Elbaxyzczyx Write a program that will accept a sequence of characters terminated by a period and will decide whether the string—without the period—is a palindrome. You may assume that the input contains only letters and blanks and is at most 80 characters long. Include a loop that allows the user to check additional strings until she or he requests that the program end. Hint: Define a static method called is Palindrome that begins as follows: /** Precondition: The array a contains letters and blanks in positions a[0] through a[used − 1]. Returns true if the string is a palindrome and false otherwise. */ public static boolean is a palindrome(char[] a int used) Your program should read the input characters into an array whose base…arrow_forwardDon't copy ASAParrow_forwardA(n) is a string within a string.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning