/*

 * Brian Kim

 * Mt. View Middle School

 * Contest 2 Junior

 * Reg Hahne

 */

 

import java.util.Scanner;

 

public class Trying

{

 

            public static void main(String[] args)

            {

                        for(int pop=0; pop<5; pop++)

                        {

                                    int num;

                                    Scanner kb = new Scanner(System.in);

                                    System.out.print("Please enter the size of the array: ");

                                    int arraySize = kb.nextInt();

                                   

                                    String[] myArray = new String[arraySize];

                                    String[] tempStatus = new String[arraySize];

                                   

                                    for(num = 0; num < arraySize; num++)

                                    {

                                                System.out.print("Please enter status #" + (num+1) + ": ");

                                                myArray[num] = kb.next();

                                    }

                                   

                                    System.out.print("Enter how many generations: ");

                                    int gen = kb.nextInt();

                                   

                                    if(arraySize == 1)

                                    {

                                                myArray[0] = "D";

                                    }

                                    else

                                    {

                                                for(int number = 0; number < gen; number++)

                                                {

                                                            for(int index = 0; index < arraySize; index++)

                                                            {

                                                                        if(index == 0)

                                                                        {

                                                                                    tempStatus[0] = myArray[1];

                                                                        }

                                                                        else if(index == arraySize-1)

                                                                        {

                                                                                    tempStatus[arraySize-1] = myArray[arraySize-2];

                                                                        }

                                                                        else

                                                                        {

                                                                                    if(myArray[index-1].equalsIgnoreCase(myArray[index+1]))

                                                                                    {

                                                                                                tempStatus[index] = "D";

                                                                                    }

                                                                                    else

                                                                                    {

                                                                                                tempStatus[index] = "A";

                                                                                    }

                                                                        }

                                                            }

                                                            for(num = 0; num < arraySize; num++)

                                                            {

                                                                        myArray[num] = tempStatus[num];

                                                    }

                       

                                                }

                                    }

                                    for(num = 0; num < arraySize; num++)

                                    {

                                    System.out.print(myArray[num] + "  ");

                                    }

                                    System.out.println("");

                        }

            }

}