题目地址:http://poj.org/problem?id=2996

 /*
题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子
模拟题 + 结构体排序:无算法,switch区分读入的字符,按照黑白的排序规则排序,再输出
注意:(转载)1,棋盘中大写字母表示的是白方棋子,小写是黑方。
2,注意棋盘的行数是从最下面开始计数的。和数组的下标相反。也就是说数组行数为8的棋盘行 数为1(数组从1开始)。
3,最容易忽略也最重要的是:白旗和黑棋在输出的时候其实排序规则是不一样的(但是棋子的类型都要按照KQRBNP顺序)。
主要是行列的优先问题:
白棋先按行数(棋盘的行编号)升序排,然后按照列升序排。解决办法:按行升序扫描输出。
黑棋先按行数(棋盘的编号)降序排,然后按照列升序排。解决办法:按行降序扫描输出。
输出的时候主要是要注意一下循环扫描的顺序就行了。
详细解释:http://poj.org/showmessage?message_id=346814
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
struct NODEb
{
char ch, col;
int pow, row;
}nodeb[];
struct NODEw
{
char ch, col;
int pow, row;
}nodew[];
int a[][];
string s[];
string ss[]; bool cmpw(NODEw x, NODEw y)
{
if (x.pow == y.pow)
{
if (x.row == y.row) return x.col < y.col;
else return x.row < y.row;
}
return x.pow < y.pow;
} bool cmpb(NODEb x, NODEb y)
{
if (x.pow == y.pow)
{
if (x.row == y.row) return x.col < y.col;
else return x.row > y.row;
}
return x.pow < y.pow;
} void work(void)
{
for (int i=; i<=; ++i)
{
int k = ;
for (int j=; j<; j+=)
{
++k;
switch (s[i][j])
{
case 'K': a[i][k] = ; break;
case 'Q': a[i][k] = ; break;
case 'R': a[i][k] = ; break;
case 'B': a[i][k] = ; break;
case 'N': a[i][k] = ; break;
case 'P': a[i][k] = ; break;
case 'k': a[i][k] = -; break;
case 'q': a[i][k] = -; break;
case 'r': a[i][k] = -; break;
case 'b': a[i][k] = -; break;
case 'n': a[i][k] = -; break;
case 'p': a[i][k] = -; break;
case ':': a[i][k] = ; break;
case '.': a[i][k] = ; break;
default: break;
}
}
}
int tb = , tw = ;
for (int i=; i<=; ++i)
{
for (int j=; j<=; ++j)
{
if (a[i][j] > )
{
nodew[++tw].pow = a[i][j];
nodew[tw].row = - i; nodew[tw].col = 'a' + j - ;
switch (a[i][j])
{
case : nodew[tw].ch = 'K'; break;
case : nodew[tw].ch = 'Q'; break;
case : nodew[tw].ch = 'R'; break;
case : nodew[tw].ch = 'B'; break;
case : nodew[tw].ch = 'N'; break;
default: break;
}
}
if (a[i][j] < )
{
nodeb[++tb].pow = -a[i][j];
nodeb[tb].row = - i; nodeb[tb].col = 'a' + j - ;
switch (a[i][j])
{
case -: nodeb[tb].ch = 'K'; break;
case -: nodeb[tb].ch = 'Q'; break;
case -: nodeb[tb].ch = 'R'; break;
case -: nodeb[tb].ch = 'B'; break;
case -: nodeb[tb].ch = 'N'; break;
default: break;
}
}
}
} sort (nodew+, nodew++tw, cmpw);
sort (nodeb+, nodeb++tb, cmpb); cout << "White: ";
for (int i=; i<=tw; ++i)
{
if (nodew[i].pow != )
cout << nodew[i].ch;
cout << nodew[i].col << nodew[i].row;
if (i != tw) cout << ',';
}
cout << endl;
cout << "Black: ";
for (int i=; i<=tb; ++i)
{
if (nodeb[i].pow != )
cout << nodeb[i].ch;
cout << nodeb[i].col << nodeb[i].row;
if (i != tb) cout << ',';
}
cout << endl;
} int main(void) //POJ 2996 Help Me with the Game
{
freopen ("I.in", "r", stdin); for (int i=; i<=; ++i)
{
cin >> ss[i]; cin >> s[i];
}
cin >> ss[]; work (); return ;
} /*
White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
*/

模拟 POJ 2996 Help Me with the Game的更多相关文章

  1. poj 2996 Help Me with the Game(模拟)

    题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...

  2. POJ 2996 &amp; 2993 国际象棋布局 模拟

    Description Your task is to read a picture of a chessboard position and print it in the chess notati ...

  3. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  4. Poj 2996 Help Me with the Game

    1.Link: http://poj.org/problem?id=2996 2.Content: Help Me with the Game Time Limit: 1000MS   Memory ...

  5. 模拟 POJ 2993 Emag eht htiw Em Pleh

    题目地址:http://poj.org/problem?id=2993 /* 题意:与POJ2996完全相反 模拟题 + 字符串处理:无算法,读入两行字符串找出相应点用used标记,输出时标记过的输出 ...

  6. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  7. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  8. 模拟 POJ 1068 Parencodings

    题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...

  9. stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram

    题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...

随机推荐

  1. Linux 4.6分支已到生命尽头 请尽快升级至Linux 4.7.1

    导读 在Linux Kernel 4.7首个维护版本发布的同时,Greg Kroah-Hartman同时也向社区发布了Linux Kernel 4.6.7版本.作为Linux 4.6分支的第7个维护版 ...

  2. 在mac上安装nodejs

    文章转载自我的个人博客  www.iwangzheng.com node.js最初是2009年发布的,目标是为聊实现事件驱动和非阻塞I/O的web服务器,应用的场景非常的广泛,有web服务器.实时应用 ...

  3. zookeeper 用法和日常运维

    本文以ZooKeeper3.4.3版本的官方指南为基础:http://zookeeper.apache.org/doc/r3.4.3/zookeeperAdmin.html,补充一些作者运维实践中的要 ...

  4. poj 1833

    http://poj.org/problem?id=1833 next_permutation这个函数是用来全排列的,按字典的序进行排列,当排列无后继的最大值时,会执行字典升序排列,相当于排序: 当排 ...

  5. 42.旋转数组的最小元素[Get min value of rotated array]

    [题目] 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个排好序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5 ...

  6. Java for LeetCode 030 Substring with Concatenation of All Words【HARD】

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  7. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

  8. ubuntu 13.10 amd64安装ia32-libs

    很多软件只有32位的,有的依赖32位库还挺严重的:从ubuntu 13.10已经废弃了ia32-libs,但可以使用多架构,安装软件或包apt-get install program:i386.有的还 ...

  9. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  10. UVA 10325 The Lottery( 容斥原理)

    The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...