## 732 - Anagrams by Stack

Moderator: Board moderators

### Re: 732 - Anagrams by Stack

can anyone help me?

I'm getting always RTE

Code: Select all
`#include <iostream>#include <string>#include <vector>using namespace std;typedef vector<int> VI;void process(string sw, string tw, VI &slet, string stack, string seq, int a, int b){    if (b == tw.size())    {        seq = seq.substr(1);        cout << seq << endl;    }    else    {        if (slet[tw[b] - 'a'] > 0)        {            slet[sw[a] - 'a']--;            process(sw, tw, slet, stack + sw[a], seq + " i", a + 1, b);            slet[sw[a] - 'a']++;        }        int stam = stack.size();        if (stam > 0 and stack[stam - 1] == tw[b])            process(sw, tw, slet, stack.substr(0, stam - 1), seq + " o", a, b + 1);    }}int main(){    string sw, tw;    while (cin >> sw >> tw)    {        cout << '[' << endl;        if (sw.size() == tw.size())        {            VI slet(26, 0), tlet(26, 0);            for (int i = 0; i < sw.size(); i++) slet[sw[i] - 'a']++;            for (int i = 0; i < tw.size(); i++) tlet[tw[i] - 'a']++;            bool valid = true;            for (int i = 0; i < 26 and valid; i++)                valid = valid and (slet[i] == tlet[i]);            if (valid) process(sw, tw, slet, "", "", 0, 0);        }        cout << ']' << endl;    }}`

I don't know in witch case it can crash...
x140l31
Learning poster

Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Previous