fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. int main() {
  8. std::string dna("ACTGCGACGGTACGCTTCGACGTAG");
  9. std::map< std::string, std::vector<int> > msvi;
  10. auto len = dna.size();
  11. for(auto i = 0; i + 3 <= len; ++i) {
  12. for(auto j = 3; i + j < len; ++j) {
  13. msvi[ dna.substr(i, j) ].push_back(i);
  14. }
  15. }
  16.  
  17. for(auto &it : msvi) {
  18. if(it.second.size() < 2) continue;
  19. cout << it.first << ':';
  20. for(auto &n : it.second) cout << n << ' ';
  21. cout << endl;
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
ACG:6 11 19 
CGA:4 17 
CGAC:4 17 
CGACG:4 17 
GAC:5 18 
GACG:5 18 
GTA:9 21