C++20 sections · 1024 units
Open in Course

Reading Multiple Inputs

Handle n test cases

The input format is common in competitive programming: first a count, then that many items. Here, you read nn (number of words), then read nn words one per line. Use a loop: for i from 1 to n, read a word and process it.

In C++, you can use cin >> word for single words or getline(cin, word) for lines with spaces. This "read count, then loop" pattern appears in hundreds of problems. Learn it now and it becomes automatic.

You'll focus on the actual problem logic instead of input handling.