rendered paste body#include <iostream>#include <stack>#include <cstdlib> using namespace std;string swap_letter(string s, int pos1, int pos2) { string new_string = s.substr(0,pos1) + s.substr(pos2,1) + s.substr(pos1+1,(pos2-pos1-1)) + s.substr(pos1,1) + s.substr(pos2+1,s.length());cout << new_string<< endl;return new_string;}int main() { // Define any necessary variables. stack<string> words; // Push our example values onto the stack. words.push("+tame"); words.push("+meat"); while ( words.size() > 0 ) { string word = words.top(); words.pop(); if ( word.substr( word.length()-1,1 ) == "+" ) { cout << word.substr(0,word.length()-1) << endl; } else { int pos = word.find_first_of("+",0); int letter_to_move = pos+1; string actual_letter = word.substr(pos+1,1); string rest = word.substr(letter_to_move+1,word.length()); for (int i = pos; i<(word.length()-pos); i++) { string new_word = word.substr(0,pos) + actual_letter + "+" + rest; rest = swap_letter(new_word, pos, pos+2); actual_letter = rest.substr(1,1); rest = rest.substr(2,rest.length()); words.push(new_word);// cout << new_word << endl; } } } return 0;}