当前位置:网站首页>POJ2996 -- Help Me with the Game(大模拟)
POJ2996 -- Help Me with the Game(大模拟)
2022-08-06 05:17:00 【abcpony】
Help Me with the Game
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6388 | Accepted: 3857 |
Description
Your task is to read a picture of a chessboard position and print it in the chess notation.
Input
The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white player are shown in upper-case letters, while the black player's pieces are lower-case letters. The letters are one of "K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). The chessboard outline is made of plus ("+"), minus ("-"), and pipe ("|") characters. The black fields are filled with colons (":"), white fields with dots (".").
Output
The output consists of two lines. The first line consists of the string "White: ", followed by the description of positions of the pieces of the white player. The second line consists of the string "Black: ", followed by the description of positions of the pieces of the black player.
The description of the position of the pieces is a comma-separated list of terms describing the pieces of the appropriate player. The description of a piece consists of a single upper-case letter that denotes the type of the piece (except for pawns, for that this identifier is omitted). This letter is immediatelly followed by the position of the piece in the standard chess notation -- a lower-case letter between "a" and "h" that determines the column ("a" is the leftmost column in the input) and a single digit between 1 and 8 that determines the row (8 is the first row in the input).
The pieces in the description must appear in the following order: King("K"), Queens ("Q"), Rooks ("R"), Bishops ("B"), Knights ("N"), and pawns. Note that the numbers of pieces may differ from the initial position because of capturing the pieces and the promotions of pawns. In case two pieces of the same type appear in the input, the piece with the smaller row number must be described before the other one if the pieces are white, and the one with the larger row number must be described first if the pieces are black. If two pieces of the same type appear in the same row, the one with the smaller column letter must appear first.
Sample Input
+---+---+---+---+---+---+---+---+ |.r.|:::|.b.|:q:|.k.|:::|.n.|:r:| +---+---+---+---+---+---+---+---+ |:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.| +---+---+---+---+---+---+---+---+ |...|:::|.n.|:::|...|:::|...|:p:| +---+---+---+---+---+---+---+---+ |:::|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |...|:::|...|:::|.P.|:::|...|:::| +---+---+---+---+---+---+---+---+ |:P:|...|:::|...|:::|...|:::|...| +---+---+---+---+---+---+---+---+ |.P.|:::|.P.|:P:|...|:P:|.P.|:P:| +---+---+---+---+---+---+---+---+ |:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.| +---+---+---+---+---+---+---+---+
Sample Output
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
本题没有特别的说明怎么做,毕竟模拟题。只是想吐槽一下模拟题一直选取不好数据类型(尤其是char和string之间的抉择!),总结就是涉及排序的最好还是用string,把最后要排序的变量放全局,排序的时候string之间交换指针指向,而char*则似乎没有类似的好方法,毕竟如果直接比较去sort,由于那些数组元素是常char*指针,是交换不了的,无法排序。一道半小时的题目写成一两个小时也是醉了。代码如下:
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;
const int maxn=100;
string arr[maxn],a[maxn],b[maxn];
int mp[300],acnt=0,bcnt=0;
void initMp()
{
mp['K']=0;
mp['Q']=1;
mp['R']=2;
mp['B']=3;
mp['N']=4;
for(int i=0;i<8;i++)
{
mp[i+'a']=i+5;
}
for(int i=0;i<10;i++)
{
mp[i+'1']=i+13;
}
}
bool cmp(string a,string b)
{
for(int i=0;i<3;i++)
{
if(mp[a[i]]<mp[b[i]])return 1;
else if(mp[a[i]]>mp[b[i]])return 0;
}
}
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
initMp();
for(int i=0;i<17;i++)cin>>arr[i];
int len=arr[1].length();
for(int i=1;i<17;i+=2)
{
for(int j=2;j<len;j+=4)
{
if(arr[i][j]=='.'||arr[i][j]==':')continue;
else if(isupper(arr[i][j]))
{
if(arr[i][j]!='P')a[acnt]+=arr[i][j];
a[acnt]+=(17-i)/2+'0';
a[acnt++]+=j/4+'a';
}
else
{
if(arr[i][j]!='p')b[bcnt]+=arr[i][j]-'a'+'A';
b[bcnt]+=(17-i)/2+'0';
b[bcnt++]+=j/4+'a';
}
}
}
sort(a,a+acnt,cmp);
for(int i=0;i<10;i++)
{
mp[i+'1']=25-i;
}
sort(b,b+bcnt,cmp);
cout<<"White: ";
for(int i=0;i<acnt;i++)
{
int l=a[i].length();
swap(a[i][l-1],a[i][l-2]);
cout<<a[i];
if(i!=acnt-1)cout<<',';
}
cout<<"\nBlack: ";
for(int i=0;i<bcnt;i++)
{
int l=b[i].length();
swap(b[i][l-1],b[i][l-2]);
cout<<b[i];
if(i!=bcnt-1)cout<<',';
}
return 0;
}边栏推荐
- Environmental sensitivity/thermal NMR/auxin-loaded/membrane-loaded/protein-loaded hydrogels
- 基于ABP和Magicodes实现Excel导出操作
- 苏三说:今年测试行业企业招聘的真相
- 牛刀小试基本语法,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本语法和变量的使用EP02
- redis的常用命令及使用特点
- 基于flask框架web代码pyinstaller打包
- 2066:【例2.3】买图书
- QT5.15编译
- 金属材料/多肽/多糖/化合物/抗体/量子点/黑磷量子点修饰水凝胶
- SkyEye在航电系统冗余设计中的应用前景
猜你喜欢

Routing - the route

【三子棋实例】C语言实现三子棋游戏

路由-route

Clion设置toolchains报错

Oracle Recovery Tools 解决ORA-600 3020故障

Bee使用postgresql数据库插入记录后返回ID值

Zabbix 5.0 Monitoring Tutorial (3)

LoRa技术有哪些应用场景?

fegin feign.FeignException: status 404 reading StudentService#getAll()

dedecms collection selection content model display complete
随机推荐
SQL语句,存储过程,触发器
初窥门径代码起手,Go lang1.18入门精炼教程,由白丁入鸿儒,首次运行golang程序EP01
瑞吉外卖项目实战Day04
VS2010编译执行自定义命令
Oracle Recovery Tools 解决ORA-600 3020故障
备份和恢复Kubernetes集群中的Etcd数据
瑞吉外卖项目实战Day03
ModuleNotFoundError: No module named ‘nonebot.adapters‘ 错误的可能解决方法
Clion sets toolchains error
A small test of basic grammar, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, basic grammar of go lang and the use of variables EP02
解决错误:DispatcherServlet爆红!!
Backup and restore Etcd data in a Kubernetes cluster
c语言进阶篇:自定义类型--位段、枚举and联合体
Develop a SQL editor with Monaco Editor
MQ基本概念详解
golang 中 map 排序
el-table filter data
dedecms collection selection content model display complete
process
一本通1340:【例3-5】扩展二叉树