Windows Of CCPC

Problem Description

In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:
 



And the 2-nd order CCPC window is shown in the figure:
 



We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k, and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.
And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.

 

 

Input

The input file contains T test samples.(1<=T<=10)

The first line of input file is an integer T.

Then the T lines contains a positive integers k , (1≤k≤10) 

 

 

Output

For each test case,you should output the answer .

 

 

Sample Input

3
1
2
3

 

Sample Output

CC
PC
CCCC
PCPC
PPCC
CPPC
CCCCCCCC
PCPCPCPC
PPCCPPCC
CPPCCPPC
PPPPCCCC
CPCPPCPC
CCPPPPCC
PCCPCPPC
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define ull unsigned long long
#define ll long long

using namespace std;

char x[1050][1050];

int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<3;i++)
        {
            for(int j=1;j<=pow(2.0,n);j++)
            {
                if(i==1)
                {
                    x[i][j]='C';
                    printf("C");
                }
                else
                {
                    if(j%2==1){
                        x[i][j]='P';
                        printf("P");
                    }

                    else{
                        x[i][j]='C';
                        printf("C");
                    }

                }
            }
            printf("\n");
        }
        int j=1,q=2;
        for(int i=3;i<=pow(2.0,n);i++)
        {
            int k;
            for(k=1;k<=pow(2.0,n);k++)
            {
                if((k%(int)pow(2.0,q-1))==0)
                {
                    if((k/(int)pow(2.0,q-1)%2)==0)
                    {
                        x[i][k]=x[j][(int)pow(2.0,q-1)];
                        printf("%c",x[i][k]);
                    }
                    else
                    {
                        if (x[j][(int)pow(2.0,q-1)] == 'C') {
                            x[i][k] = 'P';
                            printf("P");
                        } else {
                            x[i][k] = 'C';
                            printf("C");
                        }
                    }
                }
                else
                {
                    if((k/(int)pow(2.0,q-1)%2)==1)
                    {
                        x[i][k]=x[j][k%(int)pow(2.0,q-1)];
                        printf("%c",x[i][k]);
                    }
                    else
                    {
                        if (x[j][k%(int)pow(2.0,q-1)] == 'C') {
                            x[i][k] = 'P';
                            printf("P");
                        } else {
                            x[i][k] = 'C';
                            printf("C");
                        }
                    }
                }
            }
            if(pow(2.0,q-1)==j)
            {
                q++;
                j=1;
            }
            else
            {
                j++;
            }
            printf("\n");
        }
    }
    return 0;
}

 

你可能感兴趣的:(Windows Of CCPC)