///GH The RATS class
#include "std_lib_facilities.h"

/// ras is a helper function to produce the next
/// word by the reverse, add and sort procedure
vector<char> ras(vector<char> previous) {
    vector<char> backWord, sum;
    ///reverse(previous.begin(),previous.end());
    ///As per PPP8e5, we will write our own reverse procedure
    ///In two ways, one creates a new vector and leaves the old
    ///intact:
    for(int i = previous.size()-1; i >=0; --i)
        backWord.push_back(previous[i]);
    int digitSum;
    bool carry=false;
    for(int i = 0; i < previous.size(); ++i) {
        digitSum = int(previous[i])+int(backWord[i])-130;
        if(carry) ++digitSum;
        if(digitSum > 25) {
            sum.push_back(char(digitSum%26));
            carry = true;
        }
        else {
            sum.push_back(char(digitSum+65));
            carry = false;
        }
    }
    if(carry) sum.push_back('B');
    return sum;
    ///...the other reverses the word without using a new vector
    /**for(int i = 0; i < previous.size()/2; ++i){
        char temp = previous[i];
        previous[i]=previous[previous.size()-1-i];
        previous[previous.size()-1-i] = temp;
    }*/

    /**unsigned numCopy = n;
    while(numCopy!=0) {
        digits.push_back(numCopy%10);
        numCopy /= 10;
    }
    unsigned nReverse = 0, pow10 =1;
    for(int i = digits.size()-1; i >= 0; --i) {
        nReverse += digits[i]*pow10;
        pow10 *= 10;
    }
    n += nReverse;
    digits.clear();
    while(n!=0) {
        digits.push_back(n%10);
        n /= 10;
    }
    sort(digits.begin(),digits.end());
    reverse(digits.begin(),digits.end());
    n = 0; pow10 =1;
    for(int i = digits.size()-1; i >= 0; --i) {
        n += digits[i]*pow10;
        pow10 *= 10;
    }
    return n;*/
}

class Rats
{
    public:
        Rats();
        Rats(vector<char>);
        vector<vector<char> > ratSeq;
        vector<char> seed;
        void showRats();  ///print all words in sequence
};

Rats::Rats()
{
    ///ctor
}

Rats::Rats(vector<char> s) : seed(s) {
    ratSeq.push_back(seed);
    for(int i = 0; i < 4; ++i) {
        ratSeq.push_back(ras(ratSeq[i]));
        cout << "ha";
    }
}

void Rats::showRats() {
    for(int i = 0; i < ratSeq.size()-1; ++i) {
        for(int j = 0; j < ratSeq[i].size(); ++j)
            cout << ratSeq[i][j];
        cout << ", ";
        if((i+1)%6 == 0)
            cout << endl;
    }
    for(int j = 0; j < ratSeq[ratSeq.size()-1].size(); ++j)
        cout << ratSeq[ratSeq.size()-1][j];
}

/**Rats::~Rats()
{
    ///dtor
}*/
