POJ-2996 Help Me with the Game---模拟棋子
题目链接:
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---模拟棋子的更多相关文章
- poj 2996 Help Me with the Game(模拟)
题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...
- 模拟 POJ 2996 Help Me with the Game
题目地址:http://poj.org/problem?id=2996 /* 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 模拟题 + 结构体排序:无算法,switch区分读入的字符,按 ...
- POJ 2996 & 2993 国际象棋布局 模拟
Description Your task is to read a picture of a chessboard position and print it in the chess notati ...
- 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3510 Accepted: ...
- 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 ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- POJ 3371 Flesch Reading Ease 无聊恶心模拟题
题目:http://poj.org/problem?id=3371 无聊恶心题,还是不做的好,不但浪费时间而且学习英语. 不过为了做出点技术含量,写了个递归函数... 还有最后判断es,ed,le时只 ...
- 【POJ 3279 Fliptile】开关问题,模拟
题目链接:http://poj.org/problem?id=3279 题意:给定一个n*m的坐标方格,每个位置为黑色或白色.现有如下翻转规则:每翻转一个位置的颜色,与其四连通的位置都会被翻转,但注意 ...
- 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2806 Accepted: ...
- 【BZOJ3502/2288】PA2012 Tanie linie/【POJ Challenge】生日礼物 堆+链表(模拟费用流)
[BZOJ3502]PA2012 Tanie linie Description n个数字,求不相交的总和最大的最多k个连续子序列. 1<= k<= N<= 1000000. Sam ...
随机推荐
- 二分查找的变种(Java实现)
普通二分查找: 先回顾一下普通的二分查找 注意:二分查找有这样一个问题:当数组中数有重复时,比如 {3,3,3,3} 这个数组,二分查找3时,返回的是arr[1],也就是说二分查找并不会返回3第一次出 ...
- PDF加密无法做笔记
尝试打印PDF,若无法打印,可以利用PDFescape(http://www.pdfescape.com/) PDFescape是一个可以在线修改.做笔记的网站,但是在线使用有上传PDF大小限制(小于 ...
- 1-6 hibernate映射集合属性
1.集合类框架 以Tree开头都是按顺序,默认情况下是升序排列. 以Linked 开头的都是按插入顺序排列的. 2.在hibernate中要持久化集合属性时必须将其声明为接口,如 private Se ...
- [SCOI2010] 连续攻击问题
题目 Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一 ...
- JAVA 新手注意事项
1. System.exit(0); 强行关闭虚拟机 2. System.out.println("*") 输出一个*并换行 (没后面的ln表 ...
- Object.defineProperty实现数据绑定
1.Object.defineProperty方法 Object.defineProperty(obj, prop, descriptor); (1)参数: obj:目标对象 prop:需要定义的属 ...
- python装饰器使用
看了不少python关于装饰器文章,觉得还挺实用,发贴来mark一下(以前做笔记总会长时间不看就忘记,放这里应该不会忘了吧 - -) 先来看一个简单的知识点: def a(): print(" ...
- [poj1012]Joseph_Joseph
Joseph 题目大意:给你2*k个人,前k个是好人,后k个是坏人,编号从1到2*k.每次从上一个死掉的人的下一个开始查m个人并将第m个人杀死.问最后剩下的全是好人的m是多少. 注释:$1\le k ...
- 数据库(Mongodb)
1.MongoClient()函数 In [8]: import pymongo In [9]: con = pymongo.MongoClient('localhost') #建立连接 In [10 ...
- SSH相关知识
SSH(Secure Shell, 安全Shell协议)是一种加密的网络传输协议,经常用于安全的远程登录. SSH只是一种协议,可以有多种实现. OPENSSH是一种应用广泛的实现. sshd是dae ...