Created
October 27, 2017 15:52
-
-
Save victorcmadrigal/3d302f089b65b2ea756413215961d0d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
using namespace std; | |
int LineasBananas(string lineas){ | |
int x=0, bananas=0; | |
for(int i=0; i<lineas.length(); i++){ | |
lineas[i] = tolower(lineas[i]); | |
} | |
cout << lineas; | |
while(1){ | |
int pizza = lineas.find("banana", x); | |
x = pizza + 1; | |
if (pizza != -1){ | |
bananas++; | |
}else{ | |
cout<<"Contador: "<<bananas<<endl; | |
break; | |
} | |
} | |
return bananas; | |
} | |
int BuscaBananas(const char *filename){ | |
int contador =0; | |
string lineas; | |
ifstream file(filename); | |
if(file.is_open()){ | |
while(getline(file,lineas)){ | |
contador = contador + LineasBananas(lineas); | |
} | |
return contador; | |
} | |
} | |
main(){ | |
string filename = "1.txt"; | |
int veces; | |
veces = BuscaBananas(filename.c_str()); | |
cout << "Usted tiene " << veces << " Bananas en su texto "<< endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment