Найти наибольший показатель и номер цепочки

Ответить
Sanchezzz961
Сообщения: 0
Зарегистрирован: 23 сен 2014, 19:37

23 сен 2014, 19:41

Здравствуйте, как можно дописать код, чтобы программа заработала? Вот условие и сама программа:
Дано: 9 цепочек (каждая длинной не более 1 тыс. знаков).
Возвращаемое значение: ID цепочки, имеющей наибольший показатель содержания GC, за которым следует сам показатель цепочки с точностью до 2-х десятичных знаков.
Код C++:
Код:


/* Template of the assignment 1 */

// Include libraries
#include <cstdio>
#include <fstream>
#include <string>
using namespace std;

// Main function
int main() {
// Open file "rosaling_GC.txt" without any errors check
ifstream sample;
sample.open("rosalind_GC.txt");
if (!sample.good()) { // Check has file been opened
printf("%s\n", "Bad file. Does it exist?");
return -1;
}
// Define a strands' amount to process
const unsigned int STRANDS_AMOUNT = 9;
// 2 arrays keep a pair of values: id of a strand and the strand itself
// e.g.
// >strand1
// ACTGA
// GTTC
// >strand2
// CTGGC
// will be kept as ids[0] == "strand1", ids[1] == "strand2"
// strands[0] == "ACTGAGTTC", strands[1] == "CTGGC"
string ids[STRANDS_AMOUNT];
string strands[STRANDS_AMOUNT];

// Some auxiliary variables
int pos = -1;
string currentLine;
// Loop writes a pair of a strand's id and the strand to arrays
while (!sample.eof()) {
getline(sample, currentLine); // read one line from txt

if (currentLine[0] == '>') { // check if it's id
pos++;

ids[pos] = currentLine.substr(1, currentLine.length()); // fill id
strands[pos] = "";
} else { // else proceed the strand filling
int winReturnPos = currentLine.rfind('\r'); // A dirty hack aganst a windows file format
strands[pos] += currentLine.substr(0,
(winReturnPos < 0) ? currentLine.length() : winReturnPos);
}
};

// some auxiliary variables
int maxValuePosition = 0;
double maxValue = 0.0;

// ============ YOUR CODE HERE =======================



// ====================================================

printf("%s\n%.2f%%\n" , ids[maxValuePosition].c_str(), maxValue);

sample.close();
return 0;
};

Текстовый файл с данными:
http://markoutte.me/wp-content/uploads/ ... ind_GC.txt
Ответить