题目地址:POJ 2996
题意:给你一个棋盘,白棋用大写字母表示,黑棋用小写字母表示。让你按照K,Q,R,B,N,P的方式输出棋子,K,Q,R,B,N输出的格式为字母+位置,P输出的格式仅为位置。白棋的位置输出方式是列由大到小,行由小到大。黑棋的位置输出方式是列和行都是由小到大。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
char str[40][40];
int main()
{
for(int i=0; i<17; i++)
scanf("%s",&str[i]);
printf("White: ");
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘K‘)
printf("K%c%d",‘a‘+j/4,8-i/2);
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘Q‘)
printf(",Q%c%d",‘a‘+j/4,8-i/2);
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘R‘)
printf(",R%c%d",‘a‘+j/4,8-i/2);
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘B‘)
printf(",B%c%d",‘a‘+j/4,8-i/2);
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘N‘)
printf(",N%c%d",‘a‘+j/4,8-i/2);
for(int i=15; i>=1; i-=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘P‘)
printf(",%c%d",‘a‘+j/4,8-i/2);
puts("");
printf("Black: ");
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘k‘)
printf("K%c%d",‘a‘+j/4,8-i/2);
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘q‘)
printf(",Q%c%d",‘a‘+j/4,8-i/2);
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘r‘)
printf(",R%c%d",‘a‘+j/4,8-i/2);
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘b‘)
printf(",B%c%d",‘a‘+j/4,8-i/2);
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘n‘)
printf(",N%c%d",‘a‘+j/4,8-i/2);
for(int i=1; i<=15; i+=2)
for(int j=2; j<=30; j+=4)
if(str[i][j]==‘p‘)
printf(",%c%d",‘a‘+j/4,8-i/2);
puts("");
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 2996-Help Me with the Game(模拟)
原文地址:http://blog.csdn.net/u013486414/article/details/47280573