wiktortokumpel

flat

Jan 20th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //void wyswietl (string napis){
  5. // cout << napis << endl;
  6. //}
  7.  
  8. int licz_slowa(string str){
  9. int ilosc = 0;
  10.  
  11. if(str.empty()==true){
  12. return 0;
  13. }
  14.  
  15. if(str[0]!=' ') ilosc = 1;
  16. for(int i = 0; i < str.size() - 1; i++){
  17. if (str[i] == ' ' or str[i] == '\n') {
  18. ilosc++;
  19. }
  20. if (str[i+1] == ' ' and str[i] == ' ') {
  21. ilosc--;
  22. }
  23. }
  24. return ilosc;
  25. }
  26.  
  27. //bool czy_palindrom(const string& napis){
  28. // if (palindrom){
  29. // return true
  30. // }
  31. //}
  32. //
  33. int main() {
  34.  
  35. std::string str1 = "Ala ma kota";
  36.  
  37. std::string str2 = "W książce jest 10 rozdziałów po 21 stron";
  38.  
  39. std::string str3 = "W Szczebrzeszynie\nChrzaszcz\nBrzmi W Trzcinie";
  40.  
  41. std::string str4 = "radar";
  42.  
  43. std::string str5 = " ";
  44.  
  45. std::string str6 = " wyraz ";
  46.  
  47. std::string str7;
  48.  
  49.  
  50.  
  51. // wyswietl(str1);
  52. // wyswietl(str2);
  53. // wyswietl(str3);
  54. // wyswietl(str4);
  55. // wyswietl(str5);
  56. // wyswietl(str6);
  57. // wyswietl(str7);
  58.  
  59.  
  60. cout << "Ilosc slow '" << str1 << "' = " << licz_slowa(str1) << endl;
  61. cout << "Ilosc slow '" << str2 << "' = " << licz_slowa(str2) << endl;
  62. cout << "Ilosc slow '" << str3 << "' = " << licz_slowa(str3) << endl;
  63. cout << "Ilosc slow '" << str4 << "' = " << licz_slowa(str4) << endl;
  64. cout << "Ilosc slow '" << str5 << "' = " << licz_slowa(str5) << endl;
  65. cout << "Ilosc slow '" << str6 << "' = " << licz_slowa(str6) << endl;
  66. cout << "Ilosc slow '" << str7 << "' = " << licz_slowa(str7) << endl;
  67.  
  68.  
  69.  
  70. return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment