码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2996-Help Me with the Game(模拟)

时间:2015-08-04 19:13:44      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:模拟   输出   格式   

题目地址: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!