• 最近找工作的笔试题,很简单


    打印一个N*N的方阵,N为每边字符的个数( 3〈N〈20 ),要求最外层为“X”,第二层为“Y”,从第三层起每层依次打印数字0,1,2,3,...

    例子:当N =5,打印出下面的图形:

    X X X X X

    X Y Y Y X

    X Y 0 Y X

    X Y Y Y X

    X X X X X

    #include<stdio.h>

    #include<stdlib.h>

     int main(int argc,char *argv[])

    {

           int i,j,N,k=0;

           char *p;

           char Num;

           char num[10] = {'X', 'Y'};

           p = num;

          

           while ((N < 3) || (N > 20))

           {

                  scanf("%d", &N);

                 

           }

          

           for(i=1;i<=N;i++)

                  for(j=1;j<=N;j++)

                  {

                         if((i==1)||(i==N))

                         {    

                               

                                if(j<N)

                                       printf("%c",*p);

                                if(j==N)

                                       printf("%c ",*p);

                         }

                         if((i==2)||(i==(N-1)))

                         {

                                if((j==1)||(j==N))

                                {

                                       printf("%c",*p);

                                       if(j==N)

                                       printf(" ");

                                }

                                else

                                {

                                       printf("%c",*(p+1));

                                }

                         }

                         if((i>2) && (i<(N-1)))

                         {

                                      

                                if((j==1)||(j==N))

                                       printf("%c",*p);

                                if((j==2)||(j==(N-1)))

                                       printf("%c",*(p+1));

                                if(j==N)

                                       printf(" ");

                                if((j>2) && (j<(N-1)))

                                {

                                       k++;

                                       Num=k+'0'-1;

                                       if((k-1)<10)

                                              printf("%c",Num);

                                       else

                                              printf("%c",Num+7);   //如果用字母表示>10的数,只能到Nmax = 10

                         /*           else

                                              printf("%d",k-1); //如果直接用10进制数显示只需要增加输出打印位宽  */

                                }

                               

                         }  

                  }

    }

    很多问题问题未考虑,望指正!

  • 相关阅读:
    Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂
    BZOJ2756 [SCOI2012]奇怪的游戏 最大流
    Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
    [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)
    [AtCoder] Yahoo Programming Contest 2019
    Codeforces Round #538 (Div. 2) (CF1114)
    [BZOJ3625][Codeforces Round #250]小朋友和二叉树 多项式开根+求逆
    [BZOJ2341][Shoi2011]双倍回文 manacher+std::set
    [BZOJ4278] [ONTAK2015]Tasowanie 贪心+后缀数组
    [BZOJ3451] Tyvj1953 Normal 点分治+FFT
  • 原文地址:https://www.cnblogs.com/XZJHD/p/4908472.html
Copyright © 2020-2023  润新知