Advertisement
ItsMeLucifer

Wyciaganie Liczb z Tekstu C++

May 29th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     stringstream ss;
  11.     int suma,miejsce,liczba;
  12.     string konwert="";
  13.     string tekst="W roku panskim 1345, wladca Henryk 12, na rzecz swoich 143209 poddanych uchwalil dekret o 20 procentowej znizce podatkow";
  14.     for(int i=0;i<tekst.length();i++){
  15.         if(tekst.at(i)>47 &&tekst.at(i)<58){
  16.             miejsce=i;
  17.             konwert.append(1,tekst.at(i));
  18.         }
  19.         if(tekst.at(i)>64 && i>miejsce && konwert!=""){
  20.             cout<<"konwert:"<<konwert<<"|"<<endl;
  21.             ss<<konwert;
  22.             if(ss>>liczba){
  23.                 suma+=liczba;
  24.             }else{ss.clear();ss.str("");}
  25.             konwert="";
  26.         }
  27.     }
  28.     cout<<"Suma liczb wynosi: "<<suma<<endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement