zoukankan      html  css  js  c++  java
  • POJ-2996 Help Me with the Game---模拟棋子

    题目链接:

    https://vjudge.net/problem/POJ-2996

    题目大意:

    给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子

    1,棋盘中大写字母表示的是白方棋子,小写是黑方。
    2,注意棋盘的行数是从最下面开始计数的。和数组的下标相反。也就是说数组行数为8的棋盘行   数为1(数组从1开始)。一开始就写错了
    3,最容易忽略也最重要的是:白棋和黑棋在输出的时候其实排序规则是不一样的,白棋先是行号从小到大,同一行列号从小到大,黑棋先是行号从大到小,同一行列号从小到大(但是棋子的类型都要按照KQRBNP顺序)。

    模拟最重要的就是细节

    用了一些操作让代码没那么繁琐。

    还有一题输入和输出正好相反:传送门

      1 #include<iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<algorithm>
      5 #include<cmath>
      6 #include<queue>
      7 #include<stack>
      8 #include<map>
      9 using namespace std;
     10 typedef long long ll;
     11 const int maxn = 1e2 + 10;
     12 const int INF = 1 << 30;
     13 int dir[4][2] = {1,0,0,1,-1,0,0,-1};
     14 int T, n, m, x;
     15 char Map[40][40];
     16 map<char, vector<string> >M;
     17 char a[] = "kqrbn";
     18 char b[] = "KQRBN";
     19 int main()
     20 {
     21     for(int i = 0; i < 17; i++)
     22         for(int j = 0; j < 33; j++)cin >> Map[i][j];
     23     vector<string>ans1, ans2;
     24     for(int i = 1; i <= 15; i += 2)//从上往下扫描黑棋(小写字母)
     25     {
     26         for(int j = 2; j <= 30 ; j += 4)
     27         {
     28             string s;//位置字符串
     29             s += (char)(j / 4 + 'a');//列号
     30             s += (char)((17 - i) / 2 + '0');//行号 !!注意,这里最下面是编号第一行
     31             //cout<<s<<endl;
     32             if(Map[i][j] == 'p')ans1.push_back(s);
     33             for(int k = 0; k < 5; k++)
     34             {
     35                 if(Map[i][j] == a[k])
     36                 {
     37                     M[a[k]].push_back(s);
     38                 }
     39             }
     40         }
     41     }
     42     for(int i = 15; i >= 1; i -= 2)//从下往上扫描白棋(大写字母)
     43     {
     44         for(int j = 2; j <= 30; j += 4)
     45         {
     46             string s;//位置字符串
     47             s += (char)(j / 4 + 'a');//列号
     48             s += (char)((17 - i) / 2 + '0');//行号 !!注意,这里最下面是编号第一行
     49             //cout<<s<<endl;
     50             if(Map[i][j] == 'P')ans2.push_back(s);
     51             for(int k = 0; k < 5; k++)
     52             {
     53                 if(Map[i][j] == b[k])
     54                 {
     55                     M[b[k]].push_back(s);
     56                 }
     57             }
     58         }
     59     }
     60     printf("White: ");
     61     int tot = 0, c = 1;
     62     for(int i = 0; i < 5; i++)tot += M[b[i]].size();
     63     tot += ans2.size();
     64     for(int i = 0; i < 5; i++)
     65     {
     66         for(int j = 0; j < M[b[i]].size(); j++)
     67         {
     68             cout<<b[i]<<M[b[i]][j];
     69             if(c != tot)
     70             {
     71                 c++;
     72                 cout<<",";
     73             }
     74         }
     75     }
     76     for(int i = 0; i < ans2.size(); i++)
     77     {
     78         cout<<ans2[i];
     79         if(c != tot)
     80         {
     81             c++;
     82             cout<<",";
     83         }
     84     }
     85     cout<<endl;
     86     printf("Black: ");
     87     tot = 0, c = 1;
     88     for(int i = 0; i < 5; i++)tot += M[a[i]].size();
     89     tot += ans1.size();
     90     for(int i = 0; i < 5; i++)
     91     {
     92         for(int j = 0; j < M[a[i]].size(); j++)
     93         {
     94             cout<<(char)(a[i] - 32)<<M[a[i]][j];
     95             if(c != tot)
     96             {
     97                 c++;
     98                 cout<<",";
     99             }
    100         }
    101     }
    102     for(int i = 0; i < ans1.size(); i++)
    103     {
    104         cout<<ans1[i];
    105         if(c != tot)
    106         {
    107             c++;
    108             cout<<",";
    109         }
    110     }
    111     cout<<endl;
    112     return 0;
    113 }
  • 相关阅读:
    MultipartFile 多文件上传的应用
    启动关闭zookeeper集群的脚本
    分布式锁
    NFS部署教程
    Docker安装(Debian8)-构建简单的SpringBoot应用
    Nginx实战-后端应用健康检查
    分布式文件系统FastDFS安装教程
    Redis缓存使用技巧
    WebSocket原理与实践
    HashMap中ConcurrentModificationException异常解读
  • 原文地址:https://www.cnblogs.com/fzl194/p/8719061.html
Copyright © 2011-2022 走看看