Mobile coding works. A laptop is faster for long sessions.

Problem

The first line of the input contains a natural number k. The

following lines contain a text made up of one or more lines.

Determine and print how many words in the text have exactly k letters.

A word is a maximal sequence of English letters (a-z or

A-Z); digits, spaces, and punctuation marks are not part of

a word.

The data are read from standard input (in the format described), not from a

file. After reading k with cin >> k, use cin.ignore()

to skip the newline, then cin.getline for

each line of text.

Input:

The first line contains the natural number k. The following lines contain

the text, until end of input.

- 1 <= k <= 30

- the number of text lines is between 0 and 100

- each line has at most 4000 characters

Output:

The program prints to standard output a single non-negative integer: how many words

have exactly k letters.

Example:

Input:

3

un mar si o para sunt fructe

Output:

1

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output