C++ String assignment
1. Write a C++ program to reverse a given string.
2. Write a C++ program to change every letter in a given string
with the letter following it in the alphabet (ie. a becomes b, p
becomes q, z becomes a
3. Write a C++ program to capitalize the first letter of each word
of a given string. Words must be separated by only one space
4. Write a C++ program to find the largest word in a given
string.
5. Write a C++ program to sort characters (numbers and
punctuation symbols are not included) in a string
6. Write a C++ program to count all the vowels in a given string
7. Write a C++ program to count all the words in a given string
8. Write a C++ program to check whether two characters present
equally in a given string.
Example:
Sample Input: aabcdeef
Sample Output: True
9. Write a C++ program to check if a given string is a Palindrome
or not.
10. Write a C++ program to find a word in a given string which
has the highest number of repeated letters.
11. Write a C++ program to insert a dash character (-) between
two odd numbers in a given string of numbers
Example:
Sample Input: 1345789
Sample Output: Result-> 1-345-789
12. Write a C++ program to change the case (lower to upper and
upper to lower cases) of each character of a given string.
13. Write a C++ program to find the numbers in a given string and
calculate the sum of all numbers. Example:
Sample Input: w3resource from 2008
Sample Output: Sum of the numbers: 2011
14. Write a C++ program to convert a given non-negative integer
to English words.
Example:
Sample Input: 12
Sample Output: Twelve
15. Write a C++ program to find the longest common prefix from
a given array of strings.
16. Write a C++ program to find all combinations of well-formed
brackets from a given paris of parentheses.
Example:
n=2
[[]] [][]
n=3
[[]] [][] [[[]]] [[][]] [[]][] [][[]] [][][]
17. Write a C++ programming to find the length of the longest
valid (correct-formed) parentheses substring of a given string.
Example:
Original Parentheses string: [[]
Length of longest parentheses: 2
Original Parentheses string: [[]]]
Length of longest parentheses: 4
Original Parentheses string: ]]]][[[[
Length of longest parentheses: 0
18. A vowel is a syllabic speech sound pronounced without any
stricture in the vocal tract. Vowels are one of the two principal
classes of speech sounds, the other being the consonant.
Example:
Original string: w3resource
After reversing the vowels of the said string: w3resuorce
Original string: Python
After reversing the vowels of the said string: Python
Original string: Hello
After reversing the vowels of the said string: Holle
Original string: USA
After reversing the vowels of the said string: ASU
19. Write a C++ program to check whether a given string is a
subsequence of another given string. Return 1 for true and 0 for
false. Example:
word1: apple
subse1: apl
Is subse1 is the subsequence of word1? 1
word2: apple
subse2: ppe
Is subse2 is the subsequence of word2? 1
word3: ACGGTGTCGTGCTATGCTGATGCTGACTTATATGCTA
subse3: CGTTCGGCTATGCTTCTACTTATTCTA
Is subse3 is the subsequence of word3? 1
word4: CGTTCGGCTATCGTACGTTCTATTCTATGATTTCTAA
subse4: CGTTCGGCTATGCZTTCTACTTATTCTA
Is subse4 is the subsequence of word4? 0
20. Write a C++ program to remove all special characters from a
given string.
Example:
Original string: abcd $ js# @acde$
New string after removing the special characters from the said
string:
abcd js acde
21. Write a C++ program that count the number of unique
characters of two given strings.
Example:
Original Strings:
String1: Python
String2: Java
Total number of unique characters of the said two strings: 9
22. Write a C++ program to count number of duplicate characters
in a given string.
Example:
Original String:
Total number of unique characters of the said two strings.
Number of duplicate characters in the said string: 36
23. Write a C++ program to find the longest sequence of
consecutive ones in a given binary string.
Example:
Original Binary String:
1100110001
Longest sequence of consecutive ones of the said binary string:
11
24. Write a C++ program to check a given string is a title cased
string or not. Return "True" if the string is title cased string
otherwise "False".
Example:
Original String:
The Quick Brown Fox.
Check the said string is a title cased string or not!
True
25. Write a C++ program to insert a space when a lower
character follows an upper character in a given string.
Example:
Original String:
TheQuickBrownFox.
Insert white spaces between lower and uppercase Letters in the
said string:
The Quick Brown Fox.
26. Write a C++ program to identify the missing letter in a given
string (list of alphabets). The method returns, "There is no
missing letter!" if no letters are missing from the string.
Example:
Original string: abcdef
Identify the missing letter in the said string:
There is no missing letter!
27. Write a C++ program to check if a given string contains only
uppercase or only lowercase letters. Return "True" if the string is
uppercase or lowercase, otherwise "False".
Example:
Original string: ABCDEF
Check whether the said string is uppercase or lowercase: True
28. Write a C++ program that takes a string and reverses the
words of three or more lengths in a string. Return the new string.
As input characters, only spaces and letters are permitted
Example:
Original string: The quick brown fox jumps over the lazy dog
Reverse the words of three or more lengths of the said string:
ehT kciuq nworb xof spmuj revo eht yzal god