👤

Napisz program który sumuje cyfry w tekście podanym przez użytkowników. Np:"Ala ma 1 psa i 2 koty.Jola ma 10 rybek i 2 papugi." Wynik :6

Odpowiedź :

Odpowiedź:

#include <iostream>

#include <string>

#include <sstream>

int main()

{

   std::string text;

   std::getline(std::cin, text);

   std::istringstream ss(text);

   std::string word;

   int counter = 0;

   while (ss >> word){

       if(std::isdigit(word.front())){

           counter += std::stoi(word);

       }

   }

   std::cout << counter;

   return 0;

}

Wyjaśnienie: