LearnFrenzy
Sign in Take a free test

std::string · Exercise 4 of 4

std::string String Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Classic C++ string programs asked in coding interviews and exams. Write each one yourself first, then open the solution – every solution was compiled and run, and the output shown is the real output.

Question 1 Easy

Read lines until the input ends and report whether each is a palindrome, ignoring case and anything that is not a letter or digit.

Question page & discussion
Question 2 Easy

Count the vowels, consonants, digits, spaces and other characters in a sentence.

Question page & discussion
Question 3 Medium

Reverse the letters of every word in a sentence while keeping the words in their original order and the spaces where they are.

Question page & discussion
Question 4 Medium

Check pairs of phrases for anagrams by counting letters (ignoring case and spaces) in an array of 26 counters.

Question page & discussion
Question 5 Easy

Count how often each letter occurs in a word (case-insensitive) using std::map, and print the letters in alphabetical order with their counts.

Question page & discussion
Question 6 Easy

Convert a sentence to title case: the first letter of each word uppercase and the remaining letters lowercase.

Question page & discussion
Question 7 Easy

Read a line and print its longest word and the word's length; if several have the same length, keep the first.

Question page & discussion
Question 8 Medium

Compress strings such as "aabcccccaaa" to "a2b1c5a3"; if the compressed form is not shorter, return the original.

Question page & discussion
Question 9 Medium

Find the first character that occurs exactly once in each of several strings, using a count array and two passes.

Question page & discussion
Question 10 Medium

Remove repeated characters from a string, keeping only the first occurrence of each and the original order.

Question page & discussion
All exercises doneBack to std::stringRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links