forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneticsearch.cpp
70 lines (56 loc) · 1.34 KB
/
geneticsearch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int one(string pat, string all) {
int index = 0;
int total = 0;
index = all.find(pat);
while(index != -1) {
total++;
index = all.find(pat, index+1);
}
return total;
}
int two(string pat, string all) {
vector<string> p;
for(int i = 0; i < pat.size(); i++) {
string temp = pat;
temp.erase(i,1);
p.push_back(temp);
}
sort(p.begin(), p.end());
p.resize(distance(p.begin(), unique(p.begin(), p.end())));
int total = 0;
for(auto s : p) {
total += one(s, all);
}
return total;
}
int three(string pat, string all) {
string dna = "ATCG";
vector<string> p;
for(int i = 0; i < pat.size()+1; i++) {
for(int j = 0; j < 4; j++) {
string temp = pat;
temp.insert(i, 1, dna[j]);
p.push_back(temp);
}
}
sort(p.begin(), p.end());
p.resize(distance(p.begin(), unique(p.begin(), p.end())));
int total = 0;
for(auto s : p) {
total += one(s, all);
}
return total;
}
int main() {
string pat, all;
while(cin >> pat && pat != "0" && cin >> all) {
cout << one(pat, all) << " ";
cout << two(pat, all) << " ";
cout << three(pat, all) << endl;
}
}