viewing paste Unknown #15256 | Java

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import java.util.Scanner;
 
public class JerryStacks 
{
    public static void main( String[] args ) 
    {
        
        Scanner sc = new Scanner( System.in );
        int numTests = Integer.parseInt( sc.nextLine() ); // reads the number of test cases
        
        for( int i = 0; i < numTests; i++ ) 
        {
                int listSize = Integer.parseInt( sc.nextLine() );
                String[] original = new String[listSize]; // initialize original array
                String[] desired = new String[listSize]; // initialize desired array
                for( int j = 0; j < listSize; j++ )
                {
                    original[j] = sc.nextLine();
                }
                for( int k = 0; k < listSize; k++ )
                {
                    desired[k] = sc.nextLine();
                }
                
                int oc, dc;
                oc = dc = listSize; // Initialize counters for original and desired stack.
                
                int popcounter = 0;
                
                while ( oc > 0 )
                {
                    if ( original[oc-1].equals( desired[dc-1] ) )
                    {
                        oc--;
                        dc--;
                    }
                    else
                    {
                        oc--;
                        popcounter++;
                    }
                }
                System.out.println(popcounter);
                for ( int x = (popcounter); x > 0; x--)
                System.out.println(desired[x-1]);
        }
    }
}
Viewed 564 times, submitted by Guest.