zoukankan      html  css  js  c++  java
  • 北邮oj 题

    题目描述

    Every year,prince prepares a birthday gift for princess.The gift is a box,which is decorated with jewel.
    As princess grows older,the level of the jewelry box  gradually increase from A to Y.
    Every level N jewelry box will be packed in level (N-1) jewelry box(except level 1 jewelry box).
    For example,when princess was 1 year old,she got a level-A (level 1) jewelry box.When pricess was 2 years old,she got a level-B(level 2) jewelry box.The level-B(level 2)jewelry box was packed in level-A(level 1) jewelry box.
    Because prince has obsessive-compulsive disorder, there will be a paper box between two jewelry box.
    Please help prince to determine the birthday gift.

    输入格式

    The first line contains an integer T.(0<T<=20)
    Then T test cases follow.
    Each test case contains an interger N(1<=N<=25).It represents princess is N year(s) old.

    输出格式

    For each test case,output the profile of the gift.
    The uppercase letter of the level represents the jewelry box.
    The first letter 'Z' in 'ZHI' represents the paper box.

    输入样例

    2
    1
    2

    输出样例

    A
    AAAAA
    AZZZA
    AZBZA
    AZZZA
    AAAAA




     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     5 
     6 int main(int argc, char *argv[]) {
     7 int t;
     8     scanf("%d",&t);
     9     
    10     if(t==1){
    11         printf("A");
    12     }else{
    13         char box[4*t-3][4*t-3];
    14         int j;
    15         int k;
    16         for(k=0;k<4*t-3;k++){
    17             box[0][k]='A';
    18         }
    19         
    20         for(k=1;k<4*t-4;k++){
    21             box[1][k]='Z';
    22         }
    23         box[1][0]='A';
    24         box[1][4*t-4]='A';
    25         
    26         int temp;
    27         for(j=0;j<2*t-1;j++){//上半部分 
    28             if((j%2)==0&&j!=0){//偶数行 
    29                     box[j][j-1]='Z';
    30                     box[j][(4*t-3)-j]='Z';
    31                     
    32                     for(k=j;k<(4*t-3)-j;k++){
    33                         box[j][k]=box[j-2][k]+1;
    34                     }
    35                     
    36                     for(k=0;k<j;k++){
    37                         if(k!=((4*t-3)-j)&&k!=j-1){
    38                             box[j][k]=box[j-2][k];
    39                         }
    40                     }
    41                     for(k=(4*t-3)-j;k<4*t-3;k++){
    42                         if(k!=((4*t-3)-j)&&k!=j){
    43                             box[j][k]=box[j-2][k];
    44                         }
    45                     }
    46 
    47             }
    48             
    49             if((j%2)!=0&&j!=1){
    50                 for(k=0;k<4*t-3;k++){
    51                     if(k!=j-1&&k!=(4*t-3)-j){
    52                         box[j][k]=box[j-2][k];
    53                     }else{
    54                         box[j][k]='A'+(j-1)/2;
    55                     }
    56                 }
    57             }
    58         }
    59         temp=2;
    60         for(j=2*t-1;j<4*t-3;j++){
    61             for(k=0;k<4*t-3;k++){
    62             
    63             box[j][k]=box[j-temp][k];
    64             
    65                 }
    66             temp=2+temp;
    67         }
    68         
    69         
    70         for(k=0;k<4*t-3;k++){
    71             for(temp=0;temp<4*t-3;temp++){
    72                 printf("%c",box[k][temp]);
    73                 printf("%s"," ");
    74             }
    75             printf("
    ");
    76         }
    77                 
    78     }
    79     return 0;
    80 }
  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/wpzy2311/p/5312494.html
Copyright © 2011-2022 走看看