Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <cstdio>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- string decodeBWT(const string &input);
- int main()
- {
- string transformed =
- "SGGCSNTSSSFEESRWOTOSOYGL"
- "LESMDETNOEDRTSOOOTSTGERO"
- "AFFESAEEENTETEONEYRTGDTY"
- "EDNEESYEYTGEDNRLRIIETEST"
- "RSYEGUERRE.OMMM.MC...EGR"
- "RW.RFHWWE.HHMRMCHHHFWW.."
- ".A.M...IIE.SSNEEEEIARNN."
- "..HHLWHKHNMLHRNKSVRLRHWV"
- "DMLBDVRTHFBTBEERHERVDHLD"
- "HVDTGSYMN.OOO...N...SNSR"
- ".NNNNONNEAAAAOII.TW...TT"
- "TTTTWWTTTTTTP..GG.FFLW.."
- "EHVHNTTT.H.DD..RW.IALLUA"
- "ZZB.E.OIPB..BEAANRI...RR"
- "UO.OE..OEEOOUAOOOO.OIIOI"
- "IIIAOA.OAAAATTSDGSTTTL.."
- ".LNFSSII.PW..CL.IFEVFFFP"
- "LN.YH.MCCRAU....EEELEAEO"
- "TTTGUOUUEE..EOOOORUKAAEY"
- "ESIILAINWIIUSNN.L..EOOAU"
- "..SOUIAASASUEIUNSI..$..."
- ".O.YE.IAAA.....X...OFTF."
- "GGSBAJOOBPPAAOOOAAE....L"
- "........OEMLMBAH..ANZZUU";
- string result = decodeBWT(transformed);
- cout << result << endl;
- system("pause");
- return 0;
- }
- string decodeBWT(const string &input)
- {
- // Sanity check
- if(input == "") return "";
- // Create empty table
- vector<string> table(input.length(), "");
- // For every character in the string
- for(size_t i=0; i<input.length(); i++)
- {
- // Insert the character into each row at the front
- for(size_t j=0; j<table.size(); j++)
- {
- table[j] = input.substr(j, 1) + table[j];
- }
- // Sort the rows (lexicagraphic sort by strings)
- sort(table.begin(), table.end());
- }
- // Find the row that starts with '$' and return that row (with the '$' removed)
- for(size_t i=0; i<table.size(); i++)
- {
- if(table[i].at(i) == '$') return table[i].substr(1);
- }
- // In case it didn't find one
- return "?";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement