#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