👤

Napisz program w C++, który dla dowolnego wczytanego z klawiatury tekstu, wypisze
wszystkie wyrazy, o nieparzystej liczbie liter, zaczynające się na literę "p".

Z góry dziękuje : >


Odpowiedź :

Odpowiedź:

#include <iostream>

#include <sstream>

#include <algorithm>

#include <string>

int main() {

   std::string text = "pan papier pani kot pies pomidor";

   std::istringstream ss(text);

   std::string word;

   int counter = 0;

   while(ss >> word){

       if(word.length() % 2 == 1 && std::tolower(word.front()) == 'p'){

           counter++;

       }

   }

   std::cout << counter;

   return 0;

}

Wyjaśnienie:

Wynik 2, bo pan i pomidor

On Studier: Inne Pytanie