Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //void wyswietl (string napis){
- // cout << napis << endl;
- //}
- int licz_slowa(string str){
- int ilosc = 0;
- if(str.empty()==true){
- return 0;
- }
- if(str[0]!=' ') ilosc = 1;
- for(int i = 0; i < str.size() - 1; i++){
- if (str[i] == ' ' or str[i] == '\n') {
- ilosc++;
- }
- if (str[i+1] == ' ' and str[i] == ' ') {
- ilosc--;
- }
- }
- return ilosc;
- }
- //bool czy_palindrom(const string& napis){
- // if (palindrom){
- // return true
- // }
- //}
- //
- int main() {
- std::string str1 = "Ala ma kota";
- std::string str2 = "W książce jest 10 rozdziałów po 21 stron";
- std::string str3 = "W Szczebrzeszynie\nChrzaszcz\nBrzmi W Trzcinie";
- std::string str4 = "radar";
- std::string str5 = " ";
- std::string str6 = " wyraz ";
- std::string str7;
- // wyswietl(str1);
- // wyswietl(str2);
- // wyswietl(str3);
- // wyswietl(str4);
- // wyswietl(str5);
- // wyswietl(str6);
- // wyswietl(str7);
- cout << "Ilosc slow '" << str1 << "' = " << licz_slowa(str1) << endl;
- cout << "Ilosc slow '" << str2 << "' = " << licz_slowa(str2) << endl;
- cout << "Ilosc slow '" << str3 << "' = " << licz_slowa(str3) << endl;
- cout << "Ilosc slow '" << str4 << "' = " << licz_slowa(str4) << endl;
- cout << "Ilosc slow '" << str5 << "' = " << licz_slowa(str5) << endl;
- cout << "Ilosc slow '" << str6 << "' = " << licz_slowa(str6) << endl;
- cout << "Ilosc slow '" << str7 << "' = " << licz_slowa(str7) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment