Expand|Select|Wrap|Line Numbers
- string tranString( string letters){
- //determines length of letters
- int stringLength = letters.size();
- //preps before mix dimensions
- int arraySize = 1;
- int arrayHeight = 1;
- //sets extralength = 0
- int extraLength = 0;
- //determines if stringlength is a perfect square
- for ( int n = 1; n <= stringLength; n++){
- if( stringLength % n == 0 && (stringLength / n) == n){
- system("PAUSE");
- arraySize = stringLength / n;
- arrayHeight = arraySize;
- n = stringLength;
- system("PAUSE");
- }
- else if( (stringLength - n) % n == 0 && (stringLength - n) / n == n ){
- cout << n << endl;
- system("PAUSE");
- arraySize = (stringLength - n) / n;
- arrayHeight = (stringLength - n) / n;
- extraLength = n;
- system("PAUSE");
- }
- }
- //initalizes array for text
- string beforeMix[arraySize][arrayHeight];
- int row = 0;
- int subStr = 0;
- cout << "arraySize:" << arraySize << " arrayHeight" << arrayHeight << endl;
- for (row = 0, subStr = 0 ; row <= arrayHeight - 1, subStr != stringLength - extraLength; row++){
- system("PAUSE");
- for ( int column = 0; column <= arraySize - 1; column++, subStr++){
- beforeMix[column][row] = letters.substr(subStr, 1);
- cout << beforeMix[column][row] << endl;
- cout << "column:" << column << " row:" << row << " subSt:" << subStr << endl;
- }
- cout << "exited first row" << endl;
- //}
- }
- string newOrder;
- for( int column = arraySize - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
- for( row = arrayHeight - 1; row >= 0; row--){
- newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
- subStr = (beforeMix[column][row].length()) - 1;
- }
- }
- if( newOrder.length() % 2 == 0){
- newOrder.insert( (newOrder.length() / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
- }
- else
- {
- newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
- }
- return newOrder;
- }