Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string>
- #include <algorithm>
- int main()
- {
- long count = 0;
- long update = 0;
- FILE * fp = fopen("hg19.fa", "rt");
- std::string ongoing = "";
- std::string start = "";
- std::string newLine = "";
- // Each line
- while (!feof(fp))
- {
- char line[151];
- fgets(line, 150, fp);
- newLine = line;
- newLine.erase(std::remove(newLine.begin(), newLine.end(), '\n'), newLine.end());
- ongoing += newLine;
- // Check the first 3 chars until we only have 2 left
- while (ongoing.length() > 2)
- {
- start = ongoing.substr(0, 3);
- std::transform(ongoing.begin(), ongoing.end(), ongoing.begin(), ::tolower);
- if (start == "cat")
- {
- // Take off 3 chars and continue
- count++;
- update++;
- ongoing = ongoing.substr(3, ongoing.length()-3);
- } else
- {
- // Take off 1 char and continue
- ongoing = ongoing.substr(1, ongoing.length()-1);
- }
- }
- // Keep updating every 100 finds so we know it is still going
- if (update >= 1000)
- {
- printf("Count: %d\n", count);
- update = 0;
- }
- }
- fclose(fp);
- printf("Final count: %d\n", count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement