• poj2996(Help Me with the Game)


    题目大意:

        同2993、 这题是根据棋盘,分别输出棋子的位置。

    解题思路:

        模拟再模拟、我写了8000+B  你能信?我是多有耐心呢!

    代码:

      1 #include <algorithm>
      2 #include <iostream>
      3 #include <sstream>
      4 #include <cstdlib>
      5 #include <cstring>
      6 #include <cstdio>
      7 #include <string>
      8 #include <bitset>
      9 #include <vector>
     10 #include <queue>
     11 #include <stack>
     12 #include <cmath>
     13 #include <list>
     14 #include <map>
     15 #include <set>
     16 using namespace std;
     17 /***************************************/
     18 #define ll long long
     19 #define int64 __int64
     20 /***************************************/
     21 const int INF = 0x7f7f7f7f;
     22 const double eps = 1e-8;
     23 const double PIE=acos(-1.0);
     24 const int dx[]= {0,-1,0,1};
     25 const int dy[]= {1,0,-1,0};
     26 const int fx[]= {-1,-1,-1,0,0,1,1,1};
     27 const int fy[]= {-1,0,1,-1,1,-1,0,1};
     28 /***************************************/
     29 void openfile()
     30 {
     31     freopen("data.in","rb",stdin);
     32     freopen("data.out","wb",stdout);
     33 }
     34 /**********************华丽丽的分割线,以上为模板部分*****************/
     35 
     36 int main()
     37 {
     38     /* char board[18][35]=
     39      {
     40          "",
     41          " +---+---+---+---+---+---+---+---+",
     42          " |:::|...|:::|...|:::|...|:::|...|",
     43          " +---+---+---+---+---+---+---+---+",
     44          " |...|:::|...|:::|...|:::|...|:::|",
     45          " +---+---+---+---+---+---+---+---+",
     46          " |:::|...|:::|...|:::|...|:::|...|",
     47          " +---+---+---+---+---+---+---+---+",
     48          " |...|:::|...|:::|...|:::|...|:::|",
     49          " +---+---+---+---+---+---+---+---+",
     50          " |:::|...|:::|...|:::|...|:::|...|",
     51          " +---+---+---+---+---+---+---+---+",
     52          " |...|:::|...|:::|...|:::|...|:::|",
     53          " +---+---+---+---+---+---+---+---+",
     54          " |:::|...|:::|...|:::|...|:::|...|",
     55          " +---+---+---+---+---+---+---+---+",
     56          " |...|:::|...|:::|...|:::|...|:::|",
     57          " +---+---+---+---+---+---+---+---+"
     58      };  */
     59     char board[18][35];
     60     memset(board,0,sizeof(board));
     61     int i,j;
     62     int num1=0,num2=0;
     63     int numK=0,numQ=0,numR=0,numB=0,numP=0,numN=0;
     64     int numk=0,numq=0,numr=0,numb=0,nump=0,numn=0;
     65     for(i=17; i>0; i--)
     66     {
     67         for(j=1; j<=33; j++)
     68         {
     69             scanf("%c",&board[i][j]);
     70             if (board[i][j]=='K')
     71                 numK++;
     72             if (board[i][j]=='Q')
     73                 numQ++;
     74             if (board[i][j]=='R')
     75                 numR++;
     76             if (board[i][j]=='P')
     77                 numP++;
     78             if (board[i][j]=='N')
     79                 numN++;
     80             if (board[i][j]=='k')
     81                 numk++;
     82             if (board[i][j]=='q')
     83                 numq++;
     84             if (board[i][j]=='r')
     85                 numr++;
     86             if (board[i][j]=='p')
     87                 nump++;
     88             if (board[i][j]=='n')
     89                 numn++;
     90             if (board[i][j]=='B')
     91                 numB++;
     92             if (board[i][j]=='b')
     93                 numb++;
     94             if (board[i][j]>='A'&&board[i][j]<='Z')
     95                 num1++;
     96             if (board[i][j]>='a'&&board[i][j]<='z')
     97                 num2++;
     98         }
     99         getchar();
    100     }
    101     int k;
    102     int ce;
    103     char x,y;
    104     int K=0,Q=0,R=0,B=0,N=0,P=0;
    105     printf("White: ");
    106     for(i=1; i<=num1; i++)
    107         for(j=1; j<=17; j++)
    108         {
    109             ce=1;
    110             for(k=1; k<=33; k++)
    111             {
    112                 if (board[j][k]=='K')
    113                 {
    114                     x=j/2+'0';
    115                     y=(k-3)/4+'a';
    116                     K++;
    117                     ce=0;
    118 
    119                     printf("%c%c%c,",board[j][k],y,x);
    120                     board[j][k]='.';
    121                     break;
    122                 }
    123                 if (board[j][k]=='Q'&&K==numK)
    124                 {
    125                     x=j/2+'0';
    126                     y=(k-3)/4+'a';
    127                     Q++;
    128                     ce=0;
    129                     printf("%c%c%c,",board[j][k],y,x);
    130                     board[j][k]='.';
    131                     break;
    132                 }
    133                 if (board[j][k]=='R'&&Q==numQ)
    134                 {
    135                     x=j/2+'0';
    136                     y=(k-3)/4+'a';
    137                     R++;
    138                     ce=0;
    139 
    140                     printf("%c%c%c,",board[j][k],y,x);
    141                     board[j][k]='.';
    142                     break;
    143                 }
    144                 if (board[j][k]=='B'&&R==numR)
    145                 {
    146                     x=j/2+'0';
    147                     y=(k-3)/4+'a';
    148                     B++;
    149                     ce=0;
    150 
    151                     printf("%c%c%c,",board[j][k],y,x);
    152                     board[j][k]='.';
    153                     break;
    154                 }
    155                 if (board[j][k]=='N'&&B==numB)
    156                 {
    157                     x=j/2+'0';
    158                     y=(k-3)/4+'a';
    159                     N++;
    160                     ce=0;
    161 
    162                     printf("%c%c%c,",board[j][k],y,x);
    163                     board[j][k]='.';
    164                     break;
    165                 }
    166                 if (board[j][k]=='P'&&N==numN)
    167                 {
    168                     x=j/2+'0';
    169                     y=(k-3)/4+'a';
    170                     ce=0;
    171                     P++;
    172                     if (P<numP)
    173                         printf("%c%c,",y,x);
    174                     else
    175                         printf("%c%c
    ",y,x);
    176                     board[j][k]='.';
    177                     break;
    178                 }
    179             }
    180             if (!ce)
    181                 break;
    182         }
    183     int k1=0,q=0,r=0,b=0,n=0,p=0;
    184     printf("Black: ");
    185     for(i=1; i<=num2; i++)
    186         for(j=17; j>=1; j--)
    187         {
    188             ce=1;
    189             for(k=1; k<=33; k++)
    190             {
    191                 if (board[j][k]=='k')
    192                 {
    193                     x=j/2+'0';
    194                     y=(k-3)/4+'a';
    195                     k1++;
    196                     ce=0;
    197 
    198                     printf("%c%c%c,",board[j][k]-32,y,x);
    199                     board[j][k]='.';
    200                     break;
    201                 }
    202                 if (board[j][k]=='q'&&k1==numk)
    203                 {
    204                     x=j/2+'0';
    205                     y=(k-3)/4+'a';
    206                     q++;
    207                     ce=0;
    208 
    209                     printf("%c%c%c,",board[j][k]-32,y,x);
    210                     board[j][k]='.';
    211                     break;
    212                 }
    213                 if (board[j][k]=='r'&&q==numq)
    214                 {
    215                     x=j/2+'0';
    216                     y=(k-3)/4+'a';
    217                     r++;
    218                     ce=0;
    219 
    220                     printf("%c%c%c,",board[j][k]-32,y,x);
    221                     board[j][k]='.';
    222                     break;
    223                 }
    224                 if (board[j][k]=='b'&&r==numr)
    225                 {
    226                     x=j/2+'0';
    227                     y=(k-3)/4+'a';
    228                     b++;
    229                     ce=0;
    230 
    231                     printf("%c%c%c,",board[j][k]-32,y,x);
    232                     board[j][k]='.';
    233                     break;
    234                 }
    235                 if (board[j][k]=='n'&&b==numb)
    236                 {
    237                     x=j/2+'0';
    238                     y=(k-3)/4+'a';
    239                     n++;
    240                     ce=0;
    241 
    242                     printf("%c%c%c,",board[j][k]-32,y,x);
    243                     board[j][k]='.';
    244                     break;
    245                 }
    246                 if (board[j][k]=='p'&&n==numn)
    247                 {
    248                     x=j/2+'0';
    249                     y=(k-3)/4+'a';
    250                     ce=0;
    251                     p++;
    252                     if (p<nump)
    253                         printf("%c%c,",y,x);
    254                     else
    255                         printf("%c%c
    ",y,x);
    256                     board[j][k]='.';
    257                     break;
    258                 }
    259             }
    260             if (!ce)
    261                 break;
    262         }
    263     return 0;
    264 }
    265 /*
    266         "+---+---+---+---+---+---+---+---+",
    267         "|:::|...|:::|...|:::|...|:::|...|",
    268         "+---+---+---+---+---+---+---+---+",
    269         "|...|:::|...|:::|...|:::|...|:::|",
    270         "+---+---+---+---+---+---+---+---+",
    271         "|:::|...|:::|...|:::|...|:::|...|",
    272         "+---+---+---+---+---+---+---+---+",
    273         "|...|:::|...|:::|...|:::|...|:::|",
    274         "+---+---+---+---+---+---+---+---+",
    275         "|:::|...|:::|...|:::|...|:::|...|",
    276         "+---+---+---+---+---+---+---+---+",
    277         "|...|:::|...|:::|...|:::|...|:::|",
    278         "+---+---+---+---+---+---+---+---+",
    279         "|:::|...|:::|...|:::|...|:::|...|",
    280         "+---+---+---+---+---+---+---+---+",
    281         "|...|:::|...|:::|...|:::|...|:::|",
    282         "+---+---+---+---+---+---+---+---+",
    283 */
    View Code
    屌丝终有逆袭日,*******。
  • 相关阅读:
    type 、instanceof、in 和 hasOwnproperty
    从代码中抽离数据的原则
    NSNotificationCenter 通知中心传值
    imageView添加阴影和边框
    block的基本使用
    内存管理总结
    把color转成image的方法
    Instruments检测解决内存泄露以及进行性能测试
    Xcode7 修改项目名完全攻略
    UITextField的使用总结
  • 原文地址:https://www.cnblogs.com/ZhaoPengkinghold/p/3760553.html
Copyright © 2020-2023  润新知