void Append_file_to_file(char *inputPath, char *outputPath) { qint64 BUFFER_SIZE = 10*1024*1024; qint64 buffer_len = 0; QFile inputfile(inputPath); if (!inputfile.open(QIODevice::ReadOnly)) return; QFile outputfile(outputPath); if (!outputfile.open(QIODevice::WriteOnly | QIODevice::Append)) return; QDataStream inputstream(&inputfile); QDataStream outputstream(&outputfile); char* buffer = new char[BUFFER_SIZE]; while(!inputstream.atEnd()) { buffer_len = inputstream.readRawData( buffer, BUFFER_SIZE ); outputstream.writeRawData( buffer, buffer_len ); } inputfile.close(); outputfile.close(); delete[] buffer; return; }
long long Problem_11_LargestProductInGrid() { const size_t gridSize = 20; const size_t numbersInProduct = 4; std::stringstream inputstream(input); std::istream_iterator<std::string> begin(inputstream); std::istream_iterator<std::string> end; std::vector<std::string> tokens(begin, end); std::vector<long long> grid; for (auto & token : tokens) { grid.push_back(from_string<long long>(token)); } long long maxProduct = 0; for (size_t row = 0; row < gridSize; row++) { for (size_t col = 0; col < gridSize; col++) { if (col < gridSize - numbersInProduct) { long long product = 1; for (size_t i = 0; i < numbersInProduct; i++) { product *= grid[row * gridSize + col + i]; } maxProduct = std::max(maxProduct, product); } if (row < gridSize - numbersInProduct) { long long product = 1; for (size_t i = 0; i < numbersInProduct; i++) { product *= grid[(row + i) * gridSize + col]; } maxProduct = std::max(maxProduct, product); } if (row >= numbersInProduct && col < gridSize - numbersInProduct) { long long product = 1; for (size_t i = 0; i < numbersInProduct; i++) { product *= grid[(row - i) * gridSize + col + i]; } maxProduct = std::max(maxProduct, product); } if (row < gridSize - numbersInProduct && col < gridSize - numbersInProduct) { long long product = 1; for (size_t i = 0; i < numbersInProduct; i++) { product *= grid[(row + i) * gridSize + col + i]; } maxProduct = std::max(maxProduct, product); } } } return maxProduct; }
Feature DecodeString(std::string Line) { Feature Direction; std::stringstream inputstream(Line); std::string Parser; for (int n = 0; n < 2; n++) { std::getline(inputstream, Parser, ','); Direction.Results[n] = atoi(Parser.c_str()); } return Direction; }
symbol_digraph::symbol_digraph(std::istream &ins, char delimiter) { std::string line; std::string input = ""; std::vector<std::string> elements; // 1st pass on input stream int count = 0; while( std::getline(ins, line)) { input += line + "\n"; elements.clear(); split(line, delimiter, elements); for(int i = 0; i < elements.size(); ++i) { if(symbol_table.find(elements[i]) == symbol_table.end()) symbol_table[elements[i]] = count++; } } keys.resize(symbol_table.size()); for(auto it = symbol_table.begin() ; it != symbol_table.end(); ++it) { keys[it->second] = it->first; } gr = new digraph(keys.size()); //reset input stream for 2nd pass std::istringstream inputstream(input); while( std::getline(inputstream,line)) { elements.clear(); split(line, delimiter, elements); int parent = symbol_table[elements[0]]; for(int i = 1; i < elements.size(); ++i) { gr->add_edge(parent, symbol_table[elements[i]]); } } }
// each row of cost file is formated as follows: // feature_index:feature_cost // e.g.: // 1:0.8 // // fitness of feature is tuned as follows: // tuned fitness = fitness * feature_cost bool Configure::LoadFeatureCost(const std::string &cost_file) { std::ifstream inputstream(cost_file.c_str()); if (!inputstream) return false; feature_costs = new double[number_of_feature]; for (size_t i = 0; i < number_of_feature; ++i) feature_costs[i] = 1.0; std::string l; while(std::getline(inputstream, l)) { if (l.empty() || l[0] == '#') continue; size_t found = l.find(":"); int idx = boost::lexical_cast<int>(l.substr(0, found)); double cost = boost::lexical_cast<double>(l.substr(found+1)); feature_costs[idx] = cost; } enable_feature_tunning = true; return true; }
std::string Problem_13_LargeSum() { std::stringstream inputstream(input); std::istream_iterator<std::string> begin(inputstream); std::istream_iterator<std::string> end; std::vector<std::string> tokens(begin, end); std::vector<long double> numbers; // big_integer sum; for (auto & token : tokens) { long double number = from_string<long double>(token); std::cout << token << std::endl; std::cout << number << std::endl; numbers.push_back(from_string<long double>(token)); // big_integer value(token); // sum = sum + value; } long double sum = std::accumulate(std::begin(numbers), std::end(numbers), 0); return std::to_string(sum);//.substr(0, 10); // big_integer value1("37107287533902102798797998220837590246510135740250"); // big_integer value2("46376937677490009712648124896970078050417018260538"); // big_integer sum = value1 + value2; // return sum.value(); }