I have implemented a program that produces a permuted index. Actually it is this exercise: http://stackoverflow.com/questions/4015016/what-is-a-permuted-index https://stackoverflow.com/questions/4015016/what-is-a-permuted-index
I have implemented a program that produces a permuted index. Actually it is this exercise: http://stackoverflow.com/questions/4015016/what-is-a-permuted-index
I have implemented a program that produces a permuted index. Actually it is this exercise: https://stackoverflow.com/questions/4015016/what-is-a-permuted-index
Implementing permuted index in c++C++
I ahavehave implemented a program that produces a permuted index. AcctualyActually it is this excercise exercise: http://stackoverflow.com/questions/4015016/what-is-a-permuted-index Could
Could anyone tell me if I dodid something wringwrong, and if it could be done better? An
An input is for example:
andAnd result:
Implementing permuted index in c++
I ahave implemented a program that produces a permuted index. Acctualy it is this excercise : http://stackoverflow.com/questions/4015016/what-is-a-permuted-index Could anyone tell me if I do something wring and could be done better? An input is for example:
and result:
Implementing permuted index in C++
I have implemented a program that produces a permuted index. Actually it is this exercise: http://stackoverflow.com/questions/4015016/what-is-a-permuted-index
Could anyone tell me if I did something wrong, and if it could be done better?
An input is for example:
And result:
#include <iostream><vector>
#include <vector><sstream>
#include <algorithm>
using namespace std;
vector<string> generateRotationsconcatLeftAndRight(const vector<string> &splitted&left, const vector<string> &right,
const string::size_type maxLengthOfLeftLine) {
vector<string> result;ret;
for (vector<string>::size_type i = 0; i != splittedleft.size(); ++i) {
stringstd::stringstream oneLine;ss;
vector<string>ss temp<< string(splittedmaxLengthOfLeftLine - left[i].size();
, ' ')
<< left[i] << " " << right[i];
tempret.insertpush_back(tempss.beginstr(), temp.end();
- i, temp.end }
return ret;
}
vector<string> makePermutedIndex()const vector<string> &splitted); {
vector<string> sorted(splitted);
temp.erasestd::sort(tempsorted.endbegin() - i, tempsorted.end());
string::size_type maxLengthOfLeftLine = 0;
vector<string> left;
vector<string> right;
for (vector<string>:auto index :size_type jsorted) {
string rightLine, leftLine;
bool indexEncountered = 0;false;
j for (auto word : splitted) {
if ((index != temp.size(word); ++j&& !indexEncountered) {
oneLine += " "; leftLine += word;
oneLine leftLine += temp[j];" ";
}
result.push_back(oneLine); else {
} indexEncountered = true;
return result; rightLine += word;
} rightLine += " ";
}
}
vector<string> bookImplementation(const vector<string> &splitted) { maxLengthOfLeftLine = max(maxLengthOfLeftLine, leftLine.size());
vector<string> result; left.push_back(leftLine);
result = generateRotations right.push_back(splittedrightLine);
}
return concatLeftAndRight(left, right, maxLengthOfLeftLine);
}
#include <iostream>
#include <vector>
using namespace std;
vector<string> generateRotations(const vector<string> &splitted) {
vector<string> result;
for (vector<string>::size_type i = 0; i != splitted.size(); ++i) {
string oneLine;
vector<string> temp(splitted);
temp.insert(temp.begin(), temp.end() - i, temp.end());
temp.erase(temp.end() - i, temp.end());
for (vector<string>::size_type j = 0; j != temp.size(); ++j) {
oneLine += " ";
oneLine += temp[j];
}
result.push_back(oneLine);
}
return result;
}
vector<string> bookImplementation(const vector<string> &splitted) {
vector<string> result;
result = generateRotations(splitted);
}
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
vector<string> concatLeftAndRight(const vector<string> &left, const vector<string> &right,
const string::size_type maxLengthOfLeftLine) {
vector<string> ret;
for (vector<string>::size_type i = 0; i != left.size(); ++i) {
std::stringstream ss;
ss << string(maxLengthOfLeftLine - left[i].size(), ' ')
<< left[i] << " " << right[i];
ret.push_back(ss.str());
}
return ret;
}
vector<string> makePermutedIndex(const vector<string> &splitted) {
vector<string> sorted(splitted);
std::sort(sorted.begin(), sorted.end());
string::size_type maxLengthOfLeftLine = 0;
vector<string> left;
vector<string> right;
for (auto index : sorted) {
string rightLine, leftLine;
bool indexEncountered = false;
for (auto word : splitted) {
if ((index != word) && !indexEncountered) {
leftLine += word;
leftLine += " ";
}
else {
indexEncountered = true;
rightLine += word;
rightLine += " ";
}
}
maxLengthOfLeftLine = max(maxLengthOfLeftLine, leftLine.size());
left.push_back(leftLine);
right.push_back(rightLine);
}
return concatLeftAndRight(left, right, maxLengthOfLeftLine);
}