fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. std::string genome = "TTATGTTTTAAGGATGGGGCGTTAGTT";
  7. std::cout << "ATG found at position: " << genome.find("ATG") << std::endl;
  8.  
  9. while (!genome.empty())
  10. {
  11. if (genome.find("ATG", 0) == std::string::npos)
  12. {
  13. std::cout << "ATG not found, clearing genome." << std::endl;
  14. genome.clear();
  15. }
  16. else
  17. {
  18. int const startGene = genome.find("ATG", 0);
  19. std::cout << "Start of genome at position: " << startGene << std::endl;
  20. int endGene = std::min(
  21. std::min(genome.find("TAG"), genome.find("TAA")),
  22. genome.find("TGA"));
  23. std::cout << "End of genome at position: " << endGene << std::endl;
  24.  
  25.  
  26. std::string const currentGene = genome.substr(startGene + 3, endGene - (startGene + 3));
  27. std::cout << "Current gene: " << currentGene << std::endl;
  28.  
  29. if ((currentGene.length() % 3) == 0)
  30. {
  31. std::cout << currentGene << " has a length that is divisible by three." << std::endl;
  32. }
  33.  
  34. endGene += 3;
  35.  
  36. std::cout << "About to erase the following section of " << genome << std::endl;
  37. std::cout << " ";
  38. for (size_t c = 0; c < endGene; ++c)
  39. {
  40. std::cout << '^';
  41. }
  42. std::cout << std::endl;
  43. genome.erase(0, endGene);
  44.  
  45. std::cout << "Genome is now: " << genome << std::endl;
  46. }
  47. }
  48. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
ATG found at position: 2
Start of genome at position: 2
End of genome at position: 8
Current gene: TTT
TTT has a length that is divisible by three.
About to erase the following section of TTATGTTTTAAGGATGGGGCGTTAGTT
                                        ^^^^^^^^^^^
Genome is now: GGATGGGGCGTTAGTT
Start of genome at position: 2
End of genome at position: 11
Current gene: GGGCGT
GGGCGT has a length that is divisible by three.
About to erase the following section of GGATGGGGCGTTAGTT
                                        ^^^^^^^^^^^^^^
Genome is now: TT
ATG not found, clearing genome.