Skip to content

Instantly share code, notes, and snippets.

@ChrisOrozco97
Created November 22, 2015 03:17
Show Gist options
  • Save ChrisOrozco97/9bf1da6e9e0f84900cb6 to your computer and use it in GitHub Desktop.
Save ChrisOrozco97/9bf1da6e9e0f84900cb6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string read;
char file[50];
int index = 0;
int index2 = 0;
int count = 0;
cout << "Escribe el nombre de tu documento: ";
cin >> file;
ifstream read_file (file);
if (read_file.is_open()){
while (getline(read_file , read)){
index = 0;
while (index < read.length()) {
char letter = read[index];
if ( letter == 'B' || letter== 'b'){
index2 = index + 1;
char letter = read[index2];
if (letter == 'A' || letter== 'a'){
index2++;
char letter = read[index2];
if (letter == 'N' || letter== 'n'){
index2++;
char letter = read[index2];
if (letter == 'A' || letter== 'a'){
index2++;
char letter = read[index2];
if (letter == 'N' || letter== 'n'){
index2++;
char letter = read[index2];
if (letter == 'A' || letter== 'a') {
count++;
}
}
}
}
}
}
index = index + 1;
}
}
read_file.close();
}else{
cout << "Failed opening the file" << endl;
}
cout << "found " << count << " bananas" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment