Skip to content

Instantly share code, notes, and snippets.

@victorcmadrigal
Created October 27, 2017 15:52
Show Gist options
  • Save victorcmadrigal/3d302f089b65b2ea756413215961d0d9 to your computer and use it in GitHub Desktop.
Save victorcmadrigal/3d302f089b65b2ea756413215961d0d9 to your computer and use it in GitHub Desktop.
#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