Help Me with the Game(imitate)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3630 | Accepted: 2319 |
Description
Input
Output
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
Source
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<algorithm>
using namespace std;
char st[] , chess[][] ;
int a[][] ; struct white
{
char ch , row , col;
int pow ;
}wh[]; struct black
{
char ch , row , col ;
int pow ;
}bl[]; bool cmp2 (white a , white b)
{
if (a.pow < b.pow)
return ;
if (a.pow > b.pow)
return ;
if (a.pow == b.pow ) {
if (a.row == b.row)
return a.col < b.col ;
else
return a.row < b.row ;
}
} bool cmp1 (black a , black b)
{
if (a.pow < b.pow)
return ;
if (a.pow > b.pow)
return ;
if (a.pow == b.pow ) {
if (a.row == b.row)
return a.col < b.col ;
else
return a.row > b.row ;
}
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
for (int i = ; i <= ; i++) {
if (i & )
gets (st) ;
else
gets (chess[i / ]) ;
}
int k , f; for (int i = ; i <= ; i++) {
k = ;
for (int j = ; j < ; j += , k++) {
switch ( chess[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 ;
}
}
}
/* for (int i = 1 ; i <= 8 ; i++) {
for (int j = 1 ; j <= 8 ; j++) {
printf ("%d\t" , a[i][j]) ;
}
puts ("") ;
}*/
k = , f = ;
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (a[i][j] > ) {
bl[k].pow = a[i][j] ;
bl[k].row = '' + - i ;
bl[k].col = 'a' + j - ;
switch (a[i][j])
{
case : bl[k].ch = 'K' ; break ;
case : bl[k].ch = 'Q' ; break ;
case : bl[k].ch = 'R' ; break ;
case : bl[k].ch = 'B' ; break ;
case : bl[k].ch = 'N' ; break ;
default : break ;
}
k++ ;
}
if (a[i][j] < ) {
wh[f].pow = -a[i][j] ;
wh[f].row = '' + - i ;
wh[f].col = 'a' + j - ;
switch (-a[i][j])
{
case : wh[f].ch = 'K' ; break ;
case : wh[f].ch = 'Q' ; break ;
case : wh[f].ch = 'R' ; break ;
case : wh[f].ch = 'B' ; break ;
case : wh[f].ch = 'N' ; break ;
default : break ;
}
f++ ;
}
}
} sort (bl , bl + k , cmp1) ;
sort (wh , wh + f , cmp2) ; printf ("White: ") ;
for (int i = ; i < f ; i++) {
// printf ("wh[%d].pow = %d\n" , i , wh[i].pow) ;
if (wh[i].pow != )
printf ("%c" , wh[i].ch) ;
printf ("%c%c" , wh[i].col , wh[i].row ) ;
if (i != f - )
printf (",") ;
}
puts ("") ; printf ("Black: ") ;
for (int i = ; i < k ; i++) {
if (bl[i].pow != )
printf ("%c" , bl[i].ch) ;
printf ("%c%c" , bl[i].col , bl[i].row ) ;
if (i != k - )
printf (",") ;
}
puts ("") ;
return ;
}
Help Me with the Game(imitate)的更多相关文章
- Emag eht htiw Em Pleh(imitate)
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2901 Accepted: ...
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 Des ...
- Crashing Robots(imitate)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8124 Accepted: 3528 D ...
- Parencodings(imitate)
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20679 Accepted: 12436 De ...
- [JavaScript] Imitate String.Format() in c#
Definition if (!String.prototype.format) { String.prototype.format = function () { var args = argume ...
- Basic Tutorials of Redis(8) -Transaction
Data play an important part in our project,how can we ensure correctness of the data and prevent the ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
- Essential controls for web app
AUTO-COMPLETE/AUTO-SUGGEST Auto-complete using Vaadin Offer auto-suggest or auto-complete to help yo ...
- sqlmap用户手册 | WooYun知识库
sqlmap用户手册 说明:本文为转载,对原文中一些明显的拼写错误进行修正,并标注对自己有用的信息. 原文:http://drops.wooyun.org/tips/143 ============ ...
随机推荐
- Web API 基于ASP.NET Identity的Basic Authentication
今天给大家分享在Web API下,如何利用ASP.NET Identity实现基本认证(Basic Authentication),在博客园子搜索了一圈Web API的基本认证,基本都是做的Forms ...
- 从实用主义深入理解c++虚函数
记得几个月前看过C++虚函数的问题,当时其实就看懂了,最近笔试中遇到了虚函数竟然不太确定,所以还是理解的不深刻,所以想通过这篇文章来巩固下. 装逼一刻: 最近,本人思想发生了巨大的转变,在大学的时候由 ...
- [C/C++基础] C语言常用函数strlen的使用方法
函数声明:extern unsigned int strlen(char *s); 所属函数库:<string.h> 功能:返回s所指的字符串的长度,其中字符串必须以’\0’结尾 参数:s ...
- 常见面试题之ListView的复用及如何优化
经常有人问我,作为刚毕业的要去面试,关于安卓开发的问题,技术面试官会经常问哪些问题呢?我想来想去不能一股脑的全写出来,我准备把这些问题单独拿出来写,并详细的分析一下,这样对于初学者是最有帮助的.这次的 ...
- python3 入门 (二) 列表的使用
列表用于组织其它数值,即写在方括号之间.用逗号分隔开的数值列表.列表内的项目不必全是相同的类型. 列表的定义 student = ['Tom', 'Jack', 'Avril'] 添加元素 将另一个列 ...
- Git代码管理心得
一.概述: 这次按照要求进行了看似复杂,实则非常复杂并且麻烦(网上教程众多且啰嗦)的对git使用的学习,从星期六晚18:48我准备这次作业开始,直到了晚上22:44才结束电脑上的操作···(导致这篇随 ...
- PowerDesigner-如何导出建表sql脚本
1 按照数据库类型,切换数据库. Database-> Change Current DBMS... 2 生成sql脚本 Database -> Database Generation 的 ...
- Html-Css-a标签的使用
a标签去掉下划线 a{ text-decoration:none; } 或者把这个属性分别加到a标签下, a:link{ text-decoration:none; } a:visited{ text ...
- Spring-事物的隔离级别
Spring中定义了5中不同的事务隔离级别: 1. ISOLATION_DEFAULT(一般情况下使用这种配置既可) ; 这是一个PlatfromTransactionManager默认的隔离级别,使 ...
- 【ZOJ 3480】Duck Typing
题 题意 1.有t组数据,输入时每组数据之间空格隔开,输出时也要求空格隔开. 2.每组都是一行begin开始,一行end结束. 3.class ClassName[:Super] 表示声明一个类型,S ...