Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a program that counts the number of words in a given string.

Medium

Problem Statement

Create a program that counts the number of words in a given string.

Sample Input

std::string str = "Count the number of words in this string";

Sample Output

Word Count = 8

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <iostream> #include <sstream> #include <string> int main() { std::string str = "Count the number of words in this string"; // Logic to count words return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
std::string str = "Count the number of words in this string";
Expected Output
Word Count = 8