题目链接:

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

题目大意:

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

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

模拟最重要的就是细节

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

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

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + ;
const int INF = << ;
int dir[][] = {,,,,-,,,-};
int T, n, m, x;
char Map[][];
map<char, vector<string> >M;
char a[] = "kqrbn";
char b[] = "KQRBN";
int main()
{
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)cin >> Map[i][j];
vector<string>ans1, ans2;
for(int i = ; i <= ; i += )//从上往下扫描黑棋(小写字母)
{
for(int j = ; j <= ; j += )
{
string s;//位置字符串
s += (char)(j / + 'a');//列号
s += (char)(( - i) / + '');//行号 !!注意,这里最下面是编号第一行
//cout<<s<<endl;
if(Map[i][j] == 'p')ans1.push_back(s);
for(int k = ; k < ; k++)
{
if(Map[i][j] == a[k])
{
M[a[k]].push_back(s);
}
}
}
}
for(int i = ; i >= ; i -= )//从下往上扫描白棋(大写字母)
{
for(int j = ; j <= ; j += )
{
string s;//位置字符串
s += (char)(j / + 'a');//列号
s += (char)(( - i) / + '');//行号 !!注意,这里最下面是编号第一行
//cout<<s<<endl;
if(Map[i][j] == 'P')ans2.push_back(s);
for(int k = ; k < ; k++)
{
if(Map[i][j] == b[k])
{
M[b[k]].push_back(s);
}
}
}
}
printf("White: ");
int tot = , c = ;
for(int i = ; i < ; i++)tot += M[b[i]].size();
tot += ans2.size();
for(int i = ; i < ; i++)
{
for(int j = ; j < M[b[i]].size(); j++)
{
cout<<b[i]<<M[b[i]][j];
if(c != tot)
{
c++;
cout<<",";
}
}
}
for(int i = ; i < ans2.size(); i++)
{
cout<<ans2[i];
if(c != tot)
{
c++;
cout<<",";
}
}
cout<<endl;
printf("Black: ");
tot = , c = ;
for(int i = ; i < ; i++)tot += M[a[i]].size();
tot += ans1.size();
for(int i = ; i < ; i++)
{
for(int j = ; j < M[a[i]].size(); j++)
{
cout<<(char)(a[i] - )<<M[a[i]][j];
if(c != tot)
{
c++;
cout<<",";
}
}
}
for(int i = ; i < ans1.size(); i++)
{
cout<<ans1[i];
if(c != tot)
{
c++;
cout<<",";
}
}
cout<<endl;
return ;
}

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 Help Me with the Game

    题目地址:http://poj.org/problem?id=2996 /* 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 模拟题 + 结构体排序:无算法,switch区分读入的字符,按 ...

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

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

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

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

  5. 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 ...

  6. poj 1338 Ugly Numbers(丑数模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...

  7. POJ 3371 Flesch Reading Ease 无聊恶心模拟题

    题目:http://poj.org/problem?id=3371 无聊恶心题,还是不做的好,不但浪费时间而且学习英语. 不过为了做出点技术含量,写了个递归函数... 还有最后判断es,ed,le时只 ...

  8. 【POJ 3279 Fliptile】开关问题,模拟

    题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...

  9. 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted:  ...

  10. 【BZOJ3502/2288】PA2012 Tanie linie/【POJ Challenge】生日礼物 堆+链表(模拟费用流)

    [BZOJ3502]PA2012 Tanie linie Description n个数字,求不相交的总和最大的最多k个连续子序列. 1<= k<= N<= 1000000. Sam ...

随机推荐

  1. JavaScript对象入门指南

    前言 不少开发对JavaScript实现面向对象编程存在一知半解,并且不少的在项目实践中写的都是面向过程编程的代码,因此,希望能从零入手介绍面向对象的一些概念到实现简单的面向对象的例子让大家包括我自己 ...

  2. 笔记:Maven Web项目

    生成Web项目模块 生成Web项目模板和生成其他项目的模板一致,差别是指定模板的类型,执行命令如下: mvn archetype:generate -DarchetypeArtifactId=mave ...

  3. 网络通信 --> 互联网协议(一)

    互联网协议 一.概述 如何分层有不同的模型,有的模型分七层,有的分四层.这里介绍把互联网分成五层. 最底下的一层叫做"实体层"(Physical Layer),最上面的一层叫做&q ...

  4. Lucene详解

    一.lucene原理 Lucene 是apache软件基金会一个开放源代码的全文检索引擎工具包,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎.它不是一个完整的搜索应用程序 ...

  5. java中的notify和notifyAll有什么区别?

    先说两个概念:锁池和等待池 锁池:假设线程A已经拥有了某个对象(注意:不是类)的锁,而其它的线程想要调用这个对象的某个synchronized方法(或者synchronized块),由于这些线程在进入 ...

  6. MySQL之数据的insert-delete-update操作

    主要是对数据的一些基本操作:增加.删除.修改

  7. java封装的概念

    继承.封装.多态.抽象是面向对象编程的四大基本概念,其中封装尤为重要,因为从我们学习JAVA开始,就基本上接触了封装,因为JAVA中的所有程序都是写在类中的,类也能当做一种封装. 在面向对象中封装是指 ...

  8. 201621123031 《Java程序设计》第10周学习总结

    作业10-异常 1.本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 1.捕捉异常 Java中的异常捕获结构由try.catch和finally三个部分组成.其中try语句 ...

  9. Ubuntu Desktop 16.04 LTS 下成功配置Jupyter的两个python内核版本(2.7x,3.5x)

    Ubuntu  Desktop 16.04 LTS 安装好系统默认就有python两个不同版本(2.7.12和3.5.2) 现在来熟悉一下jupyter的对python这两个不同python版本的内核 ...

  10. Spring邮件发送1

    注意:邮件发送code中,邮件服务器的申请和配置是比较主要的一个环节,博主这里用的是QQ的邮件服务器.有需要的可以谷歌.百度查下如何开通. 今天看了下Spring的官方文档的邮件发送这一章节.在这里记 ...