Note that there are some explanatory texts on larger screens.

plurals
  1. POC++/C/Java: Anagrams - from original string to target;
    primarykey
    data
    text
    <p>I'm trying to solve this problem : <a href="http://uva.onlinejudge.org/external/7/732.html" rel="nofollow noreferrer">http://uva.onlinejudge.org/external/7/732.html</a>. For the given example, they give us the original word, for example <strong>TRIT</strong> and the target "anagramed" string, <strong>TIRT</strong>.</p> <p><strong>Objective:</strong> We have to output all the valid sequences of 'i' and 'o' (push and pop's, respectively) which produce the target string from the source string.</p> <p>So, I was thinking of calculate all permutations of "i" and "o" , but cutting this cases: </p> <p><strong>1)</strong> if current permutation begins with an 'o', stop checking, since all the of the next permutations will begin with this pop command and popping something from an empty stack is an invalid command.</p> <p><strong>2)</strong> if an 'o' command is found in the middle of the checking and there is nothing in the stack, skip that case.</p> <p><strong>3)</strong> if an 'i' command is found and there is nothing in the input string, skip that case.</p> <p><strong>4)</strong> if an 'o' command is found and currently expected character is not the character just popped out, then skip that case, since this will never reach to the target string.</p> <p><strong>5)</strong> don't search if the input and target strings have different lengths. </p> <p>but I think it might get me TLE anyway...</p> <p>I know the theory: permutations perhaps and backtracking all the way. I just have too many difficulties implementing it.</p> <p>could anyone please share with me some code and or ideas please?</p> <p>P.S.: Any suggestion that may decrease some execution time will be welcome , of course.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload