-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment08_ngs.cpp
More file actions
150 lines (127 loc) · 2.71 KB
/
assignment08_ngs.cpp
File metadata and controls
150 lines (127 loc) · 2.71 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
class Ngs {
private:
string ngsInfo;
int length;
public:
Ngs(string newNgsInfo): ngsInfo(newNgsInfo), length(ngsInfo.length()) {};
void print() {
cout << ngsInfo << endl;
}
int getLength() {
return length;
}
string getNgsInfo() {
return ngsInfo;
}
};
void printNgsArray(vector<Ngs> array) {
int i;
for (i = 0; i < array.size(); i++) {
array[i].print();
}
}
int findLongestStringLength(vector<Ngs> array){
int i;
int longestStringLength = 1;
int currentLength = 0;
int size = array.size();
for(i = 0; i < size; i++){
currentLength = array[i].getLength();
if(currentLength > longestStringLength) {
longestStringLength = currentLength;
}
}
return longestStringLength;
}
string radixSort(vector<Ngs>& array){
int i;
int newIndex;
int size = array.size();
int count = 0;
int longestLength = findLongestStringLength(array);
vector<Ngs> tempArray = array;
int sameCount = 1;
int maxCount = 1;
string maxNgs;
array.clear();
vector<Ngs> a;
vector<Ngs> g;
vector<Ngs> t;
vector<Ngs> c;
while (longestLength > count - 1){
for (i = 0; i < tempArray.size(); i++) {
newIndex = tempArray[i].getLength() - 1 - count;
if (newIndex == -1) {
if((array.size() > 0) && (array[array.size() - 1].getNgsInfo() == tempArray[i].getNgsInfo())) {
sameCount++;
if(sameCount > maxCount) {
maxCount = sameCount;
maxNgs = tempArray[i].getNgsInfo();
} else {
continue;
}
} else {
sameCount = 1;
}
array.push_back(tempArray[i]);
continue;
} else if (newIndex < -1) {
continue;
}
char currentChar = tempArray[i].getNgsInfo()[newIndex];
if (currentChar == 'a') {
a.push_back(tempArray[i]);
} else if (currentChar == 'c') {
c.push_back(tempArray[i]);
} else if (currentChar == 'g') {
g.push_back(tempArray[i]);
} else if (currentChar == 't') {
t.push_back(tempArray[i]);
} else {
continue;
}
}
tempArray.clear();
for(int i = 0; i < a.size(); i++) {
tempArray.push_back(a[i]);
}
a.clear();
for(int i = 0; i < c.size(); i++) {
tempArray.push_back(c[i]);
}
c.clear();
for(int i = 0; i < g.size(); i++) {
tempArray.push_back(g[i]);
}
g.clear();
for(int i = 0; i < t.size(); i++) {
tempArray.push_back(t[i]);
}
t.clear();
count++;
}
return maxNgs;
}
int main(){
ifstream inFile;
inFile.open("ngs.inp");
ofstream outFile("ngs.out");
vector<Ngs> ngs;
string max;
string tempString;
if(inFile.is_open()) {
while(getline(inFile, tempString)) {
ngs.push_back(tempString);
}
}
max = radixSort(ngs);
outFile << max;
inFile.close();
outFile.close();
return 0;
}