Advertisement
Guest User

CatFinder GENEral

a guest
Mar 25th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7.   long count = 0;
  8.   long update = 0;
  9.   FILE * fp = fopen("hg19.fa", "rt");
  10.  
  11.   std::string ongoing = "";
  12.   std::string start = "";
  13.   std::string newLine = "";
  14.  
  15.   // Each line
  16.   while (!feof(fp))
  17.   {
  18.     char line[151];
  19.     fgets(line, 150, fp);
  20.     newLine = line;
  21.     newLine.erase(std::remove(newLine.begin(), newLine.end(), '\n'), newLine.end());
  22.     ongoing += newLine;
  23.  
  24.     // Check the first 3 chars until we only have 2 left
  25.     while (ongoing.length() > 2)
  26.     {
  27.       start = ongoing.substr(0, 3);
  28.       std::transform(ongoing.begin(), ongoing.end(), ongoing.begin(), ::tolower);
  29.       if (start == "cat")
  30.       {
  31.         // Take off 3 chars and continue
  32.         count++;
  33.         update++;
  34.         ongoing = ongoing.substr(3, ongoing.length()-3);
  35.       } else
  36.       {
  37.         // Take off 1 char and continue
  38.         ongoing = ongoing.substr(1, ongoing.length()-1);
  39.       }
  40.     }
  41.  
  42.     // Keep updating every 100 finds so we know it is still going
  43.     if (update >= 1000)
  44.     {
  45.       printf("Count: %d\n", count);
  46.       update = 0;
  47.     }
  48.   }
  49.   fclose(fp);
  50.  
  51.     printf("Final count: %d\n", count);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement