Last active
October 28, 2017 16:38
-
-
Save jesuscmadrigal/d75578ad4fa94ff91a7ba37f8e16e58b 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 a = lineas.find("banana", x); | |
x = a + 1; | |
if (a != -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