博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-2996 Help Me with the Game 模拟
阅读量:4592 次
发布时间:2019-06-09

本文共 2620 字,大约阅读时间需要 8 分钟。

该题为一道纯模拟题,不需要任何算法。在选择棋子的时候定义好排序规则,将其一次排序出来。

代码如下:

#include 
#include
#include
#include
#include
using namespace std;int pos = 0;int hash[255];struct Node{ char kind; int x, y; bool operator < (Node t) const { if (hash[kind] != hash[t.kind]) { return hash[kind] > hash[t.kind]; } else if (isupper(kind)){ if (y != t.y) { return y < t.y; } else { return x < t.x; } } else { if (y != t.y) { return y > t.y; } else { return x < t.x; } } }}e[100];char s[100];void pre(){ hash['K'] = 100, hash['Q'] = 99, hash['R'] = 98; hash['B'] = 97, hash['N'] = 96, hash['P'] = 95; hash['k'] = 94, hash['q'] = 93, hash['r'] = 92; hash['b'] = 91, hash['n'] = 90, hash['p'] = 89; }void deal(int y){ int len = strlen(s); for (int i = 0; i < len; ++i) { if (isalpha(s[i])) { ++pos; e[pos].y = y; e[pos].x = ((i-2)>>2)+1; e[pos].kind = s[i]; } }}void print(){ int i; printf("White: "); for (i = 1; i <= pos && isupper(e[i].kind); ++i) { if (i == 1) { if (e[i].kind != 'P') { printf("%c%c%d", e[i].kind, e[i].x-1+'a', e[i].y); } else { printf("%c%d", e[i].x-1+'a', e[i].y); } } else { if (e[i].kind != 'P') { printf(",%c%c%d", e[i].kind, e[i].x-1+'a', e[i].y); } else { printf(",%c%d", e[i].x-1+'a', e[i].y); } } } printf("\nBlack: "); for (int j = i; j <= pos; ++j) { if (j == i) { if (e[j].kind != 'p') { printf("%c%c%d", e[j].kind-32, e[j].x-1+'a', e[j].y); } else { printf("%c%d", e[j].x-1+'a', e[j].y); } } else { if (e[j].kind != 'p') { printf(",%c%c%d", e[j].kind-32, e[j].x-1+'a', e[j].y); } else { printf(",%c%d", e[j].x-1+'a', e[j].y); } } } puts("");}int main(){ pre(); for (int i = 1; i <= 17; ++i) { gets(s); if ((i & 1) == 0) { // 说明该行为有效行 deal(9-(i>>1)); } } sort(e+1, e+1+pos); print();// system("pause"); return 0; }

转载于:https://www.cnblogs.com/Lyush/archive/2012/06/30/2570869.html

你可能感兴趣的文章
Cleartext HTTP traffic to xxx not permitted解决办法
查看>>
[Docker] Win10中安装Docker并运行Nginx镜像
查看>>
pxe批量装机
查看>>
linux典型应用对系统资源使用的特点
查看>>
linux性能分析工具Procs
查看>>
linux性能分析工具Vmstat
查看>>
linux性能分析工具Memory
查看>>
c# 选择结构
查看>>
c# 委托
查看>>
c# 接口使用
查看>>
c# 事件
查看>>
c# as运算符
查看>>
c# 调试过程
查看>>
c# 结构
查看>>
C# 中的异常处理
查看>>
c# 调试
查看>>
c# 使用序列化
查看>>
c# VS.NET 中的调试工具
查看>>
c# System.Array
查看>>
c# StringBuilder类
查看>>