Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std ;
- const string wzorzec = "banany";
- int main()
- {
- ifstream czytaj ;
- ofstream zapisz;
- czytaj.open("hejtnabanany.txt");
- if (!czytaj){
- cout<<"nie udalo sie otworzyc banany.txt"<<endl;
- return 1 ;
- }
- int licznik = 0;
- int ktoryznakzkolei=0;
- int zle=0;
- int pozycja = 0;
- /*while(czytaj>>slowo)
- {
- if(slowo==wzorzec || slowo==wzorzec+")
- licznik++;
- }*/
- char znak;
- while( czytaj>>znak )
- {
- ktoryznakzkolei++;
- if(znak == wzorzec[pozycja]){
- pozycja++;
- if( pozycja >= wzorzec.length() ){
- licznik++;
- pozycja=0;
- cout<<"Znalazlem sobie " << wzorzec << " po " << zle << " zlych znakach" << endl;
- zle=0;
- }
- }else{
- pozycja=0;
- zle++;
- }
- }
- czytaj.close();
- zapisz.open("rezultat.txt");
- zapisz<<wzorzec<<endl;
- zapisz<<"wystapilo " <<licznik<<" razy" <<endl;
- zapisz.close();
- cout<<licznik<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement