Skip to content

Instantly share code, notes, and snippets.

@Adals20
Created May 2, 2017 17:07
Show Gist options
  • Save Adals20/63be5cd1d070099efd1d575230e6eb3e to your computer and use it in GitHub Desktop.
Save Adals20/63be5cd1d070099efd1d575230e6eb3e 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 foundtop = lineas.find("banana", x);
x = foundtop + 1;
if (foundtop != -1){
bananas++;
}else{
//cout<<"Contador: "<<bananas<<endl;
break;
}
}
return bananas;
}
int EncuentraBananas(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 = "Banana.txt";
int veces;
veces = EncuentraBananas(filename.c_str());
cout << "Usted tiene " << veces << " Bananas en su texto\n";
cout <<" ____ ___\n";
cout <<" | _ \ ___ _ _.' _ `.\n";
cout <<" _ | [_) )' _ `._ _ ___ ! \ | | (_) | _\n";
cout <<" |:;.| _ <| (_) | \ | |' _ `| \| | _ | .:;|\n";
cout <<" | `.[_) ) _ | \| | (_) | | | | |.',..|\n";
cout <<" ':. `. /| | | | | _ | |\ | | |.' :;::'\n";
cout <<" !::, `-!_| | | |\ | | | | | \ !_!.' ':;!\n";
cout <<" !::; ::;:!.!.\_!_!_!.!-'-':;:'' '''!\n";
cout <<" ';:' `::;::;' '' ., .\n";
cout <<" `: .,. `' .::... . .::;::;'\n";
cout <<" `..:;::;:.. ::;::;:;:;, :;::;'\n";
cout <<" '-:;::;:;: ':;::;:'' ;.-'\n";
cout <<" ""`---...________...---'""\n";
cout <<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment