Skip to content

Instantly share code, notes, and snippets.

@samir96
Created April 30, 2015 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samir96/651ad13bf071c3992fd0 to your computer and use it in GitHub Desktop.
Save samir96/651ad13bf071c3992fd0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <fstream>
using namespace std;
void check_banana (string banana){
ifstream AbrirBanana;
AbrirBanana.open(banana);
string col;
int n = 0;
while(AbrirBanana.tellg() != -1){
AbrirBanana >> col;
for(int i = 0; i< col.size(); i++){
if( (col[i] == 'B' or col[i] == 'b') and
(col[i+1] == 'A' or col[i+1] == 'a') and
(col[i+2] == 'N' or col[i+2] == 'n') and
(col[i+3] == 'A' or col[i+3] == 'a') and
(col[i+4] == 'N' or col[i+4] == 'n') and
(col[i+5] == 'A' or col[i+5] == 'a') )
n++;
}
}
cout<<"La cantidad de veces que está escrita la palabra banana es: "<<n<<endl;
}
int main(){
check_banana("banana.txt");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment