Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- string konwersja(string slowo)
- {
- for(unsigned i = 0; i < slowo.size(); ++i)
- if(slowo[i] >= 'A' && slowo[i] <= 'Z')
- slowo[i] += 32;
- string wynik = "";
- for(unsigned i = 0; i < slowo.size(); ++i)
- if((slowo[i] >= 'a' && slowo[i] <= 'z') || (slowo[i] >= '0' && slowo[i] <= '9'))
- wynik += slowo[i];
- return wynik;
- }
- unsigned ilosc_slow(string wpis_slowo, ifstream& hamlet)
- {
- unsigned i=0;
- string slowa;
- wpis_slowo = konwersja(wpis_slowo);
- while(hamlet >> slowa)
- {
- if (wpis_slowo == konwersja(slowa))
- {
- i++;
- }
- }
- hamlet.close();
- return i;
- }
- int main()
- {
- string wpis_slowo;
- cout << "Podaj szukane slowo: " << endl;
- cin >> wpis_slowo;
- ifstream plik;
- plik.open("hamlet.txt");
- if(plik.good())
- {
- cout << ilosc_slow(wpis_slowo, plik) << endl;
- plik.close();
- }
- /*string slowo = "SWORD.";
- slowo = konwersja(slowo);
- cout << slowo << endl;*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement