题目地址:http://poj.org/problem?id=2996

  1. /*
  2. 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子
  3. 模拟题 + 结构体排序:无算法,switch区分读入的字符,按照黑白的排序规则排序,再输出
  4. 注意:(转载)1,棋盘中大写字母表示的是白方棋子,小写是黑方。
  5. 2,注意棋盘的行数是从最下面开始计数的。和数组的下标相反。也就是说数组行数为8的棋盘行 数为1(数组从1开始)。
  6. 3,最容易忽略也最重要的是:白旗和黑棋在输出的时候其实排序规则是不一样的(但是棋子的类型都要按照KQRBNP顺序)。
  7. 主要是行列的优先问题:
  8. 白棋先按行数(棋盘的行编号)升序排,然后按照列升序排。解决办法:按行升序扫描输出。
  9. 黑棋先按行数(棋盘的编号)降序排,然后按照列升序排。解决办法:按行降序扫描输出。
  10. 输出的时候主要是要注意一下循环扫描的顺序就行了。
  11. 详细解释:http://poj.org/showmessage?message_id=346814
  12. */
  13. #include <cstdio>
  14. #include <iostream>
  15. #include <algorithm>
  16. #include <cstring>
  17. #include <cmath>
  18. #include <string>
  19. #include <map>
  20. #include <queue>
  21. #include <vector>
  22. using namespace std;
  23. const int MAXN = 1e6 + ;
  24. const int INF = 0x3f3f3f3f;
  25. struct NODEb
  26. {
  27. char ch, col;
  28. int pow, row;
  29. }nodeb[];
  30. struct NODEw
  31. {
  32. char ch, col;
  33. int pow, row;
  34. }nodew[];
  35. int a[][];
  36. string s[];
  37. string ss[];
  38. bool cmpw(NODEw x, NODEw y)
  39. {
  40. if (x.pow == y.pow)
  41. {
  42. if (x.row == y.row) return x.col < y.col;
  43. else return x.row < y.row;
  44. }
  45. return x.pow < y.pow;
  46. }
  47. bool cmpb(NODEb x, NODEb y)
  48. {
  49. if (x.pow == y.pow)
  50. {
  51. if (x.row == y.row) return x.col < y.col;
  52. else return x.row > y.row;
  53. }
  54. return x.pow < y.pow;
  55. }
  56. void work(void)
  57. {
  58. for (int i=; i<=; ++i)
  59. {
  60. int k = ;
  61. for (int j=; j<; j+=)
  62. {
  63. ++k;
  64. switch (s[i][j])
  65. {
  66. case 'K': a[i][k] = ; break;
  67. case 'Q': a[i][k] = ; break;
  68. case 'R': a[i][k] = ; break;
  69. case 'B': a[i][k] = ; break;
  70. case 'N': a[i][k] = ; break;
  71. case 'P': a[i][k] = ; break;
  72. case 'k': a[i][k] = -; break;
  73. case 'q': a[i][k] = -; break;
  74. case 'r': a[i][k] = -; break;
  75. case 'b': a[i][k] = -; break;
  76. case 'n': a[i][k] = -; break;
  77. case 'p': a[i][k] = -; break;
  78. case ':': a[i][k] = ; break;
  79. case '.': a[i][k] = ; break;
  80. default: break;
  81. }
  82. }
  83. }
  84. int tb = , tw = ;
  85. for (int i=; i<=; ++i)
  86. {
  87. for (int j=; j<=; ++j)
  88. {
  89. if (a[i][j] > )
  90. {
  91. nodew[++tw].pow = a[i][j];
  92. nodew[tw].row = - i; nodew[tw].col = 'a' + j - ;
  93. switch (a[i][j])
  94. {
  95. case : nodew[tw].ch = 'K'; break;
  96. case : nodew[tw].ch = 'Q'; break;
  97. case : nodew[tw].ch = 'R'; break;
  98. case : nodew[tw].ch = 'B'; break;
  99. case : nodew[tw].ch = 'N'; break;
  100. default: break;
  101. }
  102. }
  103. if (a[i][j] < )
  104. {
  105. nodeb[++tb].pow = -a[i][j];
  106. nodeb[tb].row = - i; nodeb[tb].col = 'a' + j - ;
  107. switch (a[i][j])
  108. {
  109. case -: nodeb[tb].ch = 'K'; break;
  110. case -: nodeb[tb].ch = 'Q'; break;
  111. case -: nodeb[tb].ch = 'R'; break;
  112. case -: nodeb[tb].ch = 'B'; break;
  113. case -: nodeb[tb].ch = 'N'; break;
  114. default: break;
  115. }
  116. }
  117. }
  118. }
  119. sort (nodew+, nodew++tw, cmpw);
  120. sort (nodeb+, nodeb++tb, cmpb);
  121. cout << "White: ";
  122. for (int i=; i<=tw; ++i)
  123. {
  124. if (nodew[i].pow != )
  125. cout << nodew[i].ch;
  126. cout << nodew[i].col << nodew[i].row;
  127. if (i != tw) cout << ',';
  128. }
  129. cout << endl;
  130. cout << "Black: ";
  131. for (int i=; i<=tb; ++i)
  132. {
  133. if (nodeb[i].pow != )
  134. cout << nodeb[i].ch;
  135. cout << nodeb[i].col << nodeb[i].row;
  136. if (i != tb) cout << ',';
  137. }
  138. cout << endl;
  139. }
  140. int main(void) //POJ 2996 Help Me with the Game
  141. {
  142. freopen ("I.in", "r", stdin);
  143. for (int i=; i<=; ++i)
  144. {
  145. cin >> ss[i]; cin >> s[i];
  146. }
  147. cin >> ss[];
  148. work ();
  149. return ;
  150. }
  151. /*
  152. White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
  153. Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
  154. */

模拟 POJ 2996 Help Me with the Game的更多相关文章

  1. poj 2996 Help Me with the Game(模拟)

    题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...

  2. POJ 2996 &amp; 2993 国际象棋布局 模拟

    Description Your task is to read a picture of a chessboard position and print it in the chess notati ...

  3. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  4. Poj 2996 Help Me with the Game

    1.Link: http://poj.org/problem?id=2996 2.Content: Help Me with the Game Time Limit: 1000MS   Memory ...

  5. 模拟 POJ 2993 Emag eht htiw Em Pleh

    题目地址:http://poj.org/problem?id=2993 /* 题意:与POJ2996完全相反 模拟题 + 字符串处理:无算法,读入两行字符串找出相应点用used标记,输出时标记过的输出 ...

  6. 模拟 POJ 1573 Robot Motion

    题目地址:http://poj.org/problem?id=1573 /* 题意:给定地图和起始位置,robot(上下左右)一步一步去走,问走出地图的步数 如果是死循环,输出走进死循环之前的步数和死 ...

  7. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  8. 模拟 POJ 1068 Parencodings

    题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...

  9. stack(数组模拟) POJ 2559 Largest Rectangle in a Histogram

    题目传送门 /* 题意:宽度为1,高度不等,求最大矩形面积 stack(数组模拟):对于每个a[i]有L[i],R[i]坐标位置 表示a[L[i]] < a[i] < a[R[i]] 的极 ...

随机推荐

  1. zstu.4194: 字符串匹配(kmp入门题&& 心得)

    4194: 字符串匹配 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 206  Solved: 78 Description 给你两个字符串A,B,请 ...

  2. 教你如何---构建良好的windows程序(初学者必看)

    一使用菜单栏和工具栏 1.菜单栏和工具栏有什么作用和优点: 通过菜单栏把应用程序的功能进行分组,能够方便用户查找和使用,下图所示的菜单栏包含的每一项都是顶层菜单项,顶层菜单项下的选项称为”子菜单”或” ...

  3. MVC中html转义问题(直接输出html的方法)

    MVC中如果用@string(string是包含html代码的字符串)形式输出字符串,那么对应的html标签会自动转义,如果想直接输出html可用以下方法: @(new HtmlString( &qu ...

  4. poj2485 Highways

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  5. HDOJ 2544

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  6. C#中Const和Readonly的区别

    const 的概念就是一个包含不能修改的值的变量.常数表达式是在编译时可被完全计算的表达式.因此不能从一个变量中提取的值来初始化常量.如果 const int a = b+1;b是一个变量,显然不能再 ...

  7. 夏令时 DST (Daylight Saving Time) java中的夏令时【转】

    1916年,德国首先实行夏令时,英国因为怕德国会从中得到更大的效益,因此紧跟着也采取了夏令时 1986年至1991年,中华人民共和国在全国范围实行了六年夏令时 サマータイム 夏時間(日本现在没有实行夏 ...

  8. 【转】Oracle数据库中Sequence的用法

    在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方. 1.Create Sequence (注释:你需要有CREATE S ...

  9. poj_2674 弹性碰撞

    题目大意 给定一条直线,长度为L 表示区间[0, L].在直线上开始放置N个人,每个人有一个初始位置pos(用到直线上端点0的距离表示)和初始方向dir('p' 或 'P' 表示向端点L行走, 'n' ...

  10. object-c学习笔记

    原文地址 最近开始学习object-c,分享一下学习oc的经验以及对oc的理解,其中难免会有错误,请大家理解. 对初学者来说,objective-c存在了很多令人费解的写法,当然也包括我! 我刚开始看 ...