POJ 2996 Help Me with the Game (模拟)
来源:互联网 发布:手机男变女声音软件 编辑:程序博客网 时间:2024/06/06 13:04
题目链接:http://poj.org/problem?id=2996
POJ训练计划中的模拟都是很棒的模拟,也很有代表性。
这个题讲的是给你一个国际象棋棋盘,写程序打印出黑白双方的棋子,以及棋子的坐标。
但是需要注意的国际棋盘的坐标问题
如下图这个国际棋盘
可以看到数字轴和字母轴的方向以及增减关系。
所以在这个题的统计的时候需要进行坐标转换,因为已经做过类似的方法了,这个也不是问题。
总之就是个模拟,代码如下:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>struct node{ char x,y;}zb[10000];char MAP[20][40];int cmp (const void * a,const void * b){ struct node *ta = (struct node *)a; struct node *tb = (struct node *)b; if (ta->y == tb->y) return ta->x - tb->x; return ta->y - tb->y;}int cmp1 (const void * a,const void * b){ struct node *ta = (struct node *)a; struct node *tb = (struct node *)b; if (ta->y == tb->y) return ta->x - tb->x; return tb->y - ta->y;}int fin(char c){ int i,k; int s = 0; int x = 0,y = 0;; for (i = 1,y = 0;i < 17;y++,i += 2) { for (k = 2,x = 0;k < 33;x++,k += 4) if (MAP[i][k] == c) { zb[s].x = x; zb[s++].y = 8 - y; //printf ("!%d - %d!\n",x,8 - y); } } return s;}int main(){ int i,k; int n; for (i = 0;i < 17;i++) scanf ("%s",MAP[i]); printf ("White: "); n = fin('K'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) printf ("K%c%d,",zb[i].x + 'a',zb[i].y); n = fin('Q'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) printf ("Q%c%d,",zb[i].x + 'a',zb[i].y); n = fin('R'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) printf ("R%c%d,",zb[i].x + 'a',zb[i].y); n = fin('B'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) printf ("B%c%d,",zb[i].x + 'a',zb[i].y); n = fin('N'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) printf ("N%c%d,",zb[i].x + 'a',zb[i].y); n = fin('P'); qsort (zb,n,sizeof (zb[0]),cmp); for (i = 0;i < n;i++) { printf ("%c%d",zb[i].x + 'a',zb[i].y); if (i < n - 1) printf(","); else printf ("\n"); } printf ("Black: "); n = fin('k'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) printf ("K%c%d,",zb[i].x + 'a',zb[i].y); n = fin('q'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) printf ("Q%c%d,",zb[i].x + 'a',zb[i].y); n = fin('r'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) printf ("R%c%d,",zb[i].x + 'a',zb[i].y); n = fin('b'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) printf ("B%c%d,",zb[i].x + 'a',zb[i].y); n = fin('n'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) printf ("N%c%d,",zb[i].x + 'a',zb[i].y); n = fin('p'); qsort (zb,n,sizeof (zb[0]),cmp1); for (i = 0;i < n;i++) { printf ("%c%d",zb[i].x + 'a',zb[i].y); if (i < n - 1) printf(","); else printf ("\n"); } return 0;}
我的博客:http://blog.csdn.net/codehypo
1 0
- POJ 2996 Help Me with the Game 大模拟
- poj 2996 Help Me with the Game(模拟)
- POJ 2996:Help Me with the Game 模拟题
- POJ 2996 Help Me with the Game (模拟)
- POJ 2996 Help Me with the Game 模拟
- poj 2996 Help Me with the Game(模拟)
- poj-2996-2993-Help Me with the Game-模拟法
- POJ 2996-Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game 国际象棋,模拟
- POJ 2996Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game(模拟)
- 模拟 Help Me with the Game 2996
- Poj 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- Java程序员应该知道的10个Eclipse调试技巧
- 关于百度平台的git shell 提交方法
- 整理 git的使用--菜鸟篇git
- UBUNTU 恢复模式修改密码
- MFC Windows程序设计源码免费下载
- POJ 2996 Help Me with the Game (模拟)
- 【经验小谈】百度地图之 请输入正确的key 百度地图老版本key错误
- iOS开发- 隐藏键盘总结
- opencv查找轮廓---cvFindContours && cvDrawCountours
- 矩形类中运算符重载
- 词典查找算法
- 黑马程序员_学习笔记10——引用类型与值类型,继承,访问修饰符,里氏转换
- 【vb数据库】--SQL
- Android开发书籍推荐