poj-2993-Emag eht htiw Em Pleh && poj-2996-Help Me with the Game
来源:互联网 发布:成都犀牛软件培训 编辑:程序博客网 时间:2024/04/30 09:31
poj-2993 poj-2996
先说2996的题意:
给一张棋盘,按KQRBKNP的顺序输出棋子的位置
其中大写字母代表白棋,小写字母代表黑棋
有一点需要注意,左下角是(1, 1)点
细心一些,耐心一些就可以AC了
#include <iostream> #include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <string> #include <map>#include <algorithm>#define N 13#define ll long longusing namespace std;char Map[10][10];string s;int main(){#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif int i, j, l; bool flag = true; getline(cin, s); for (i = 0; i < 8; i++){ getline(cin, s); l = s.size(); for (j = 0; j < 8; j++){ Map[i][j] = s[2+j*4]; } getline(cin, s); } printf("White: "); for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'K'){ if (flag){ flag = false; }else{ printf(","); } printf("K%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'Q'){ printf(",Q%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'R'){ printf(",R%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'B'){ printf(",B%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'N'){ printf(",N%c%d", j+'a', 8-i); } } } for (i = 7; i >= 0; i--){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'P'){ printf(",%c%d", j+'a', 8-i); } } } puts(""); printf("Black: "); flag = true; for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'k'){ if (flag){ flag = false; }else{ printf(","); } printf("K%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'q'){ printf(",Q%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'r'){ printf(",R%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'b'){ printf(",B%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'n'){ printf(",N%c%d", j+'a', 8-i); } } } for (i = 0; i < 8; i++){ for (j = 0; j < 8; j++){ if (Map[i][j] == 'p'){ printf(",%c%d", j+'a', 8-i); } } } puts(""); return 0;}
2993和2996是相反的,给出每个棋子的位置,输出棋盘
#include <iostream> #include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <string> #include <map>#include <algorithm>#define N 13#define ll long longusing namespace std;char Map[10][10];string s;int main(){#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif int i, j, k, l, x, y; char c; getline(cin, s); l = s.size(); for (i = 0; 7+i*4 < l; i++){ c = s[7+i*4]; if (c < 'A' || c > 'Z') break; x = s[9+i*4]-'0'; y = s[8+i*4]-'a'; Map[x][y] = c; } for(i = 7+i*4; i < l; i+=3){ x = s[i+1]-'0'; y = s[i]-'a'; Map[x][y] = 'P'; } getline(cin, s); l = s.size(); for (i = 0; 7+i*4 < l; i++){ c = s[7+i*4]+32; if (c < 'a' || c > 'z') break; x = s[9+i*4]-'0'; y = s[8+i*4]-'a'; Map[x][y] = c; } for(i = 7+i*4; i < l; i+=3){ x = s[i+1]-'0'; y = s[i]-'a'; Map[x][y] = 'p'; } puts("+---+---+---+---+---+---+---+---+"); for (i = 8; i > 0; i--){ printf("|"); for (j = 0; j < 8; j++){ if ((i+j)&1){ printf(":"); }else{ printf("."); } if ((Map[i][j] >= 'a' && Map[i][j] <= 'z') || (Map[i][j] >= 'A' && Map[i][j] <= 'Z')){ printf("%c", Map[i][j]); }else{ if ((i+j)&1){ printf(":"); }else{ printf("."); } } if ((i+j)&1){ printf(":|"); }else{ printf(".|"); } } cout << endl; puts("+---+---+---+---+---+---+---+---+"); } return 0;}
0 0
- POJ 2996 Help Me with the Game && POJ 2993 Emag eht htiw Em Pleh
- poj-2993-Emag eht htiw Em Pleh && poj-2996-Help Me with the Game
- Poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- Poj 2993 Emag eht htiw Em Pleh
- POJ 2993:Emag eht htiw Em Pleh
- Emag eht htiw Em Pleh(POJ--2993
- poj 2993 Emag eht htiw Em Pleh
- POJ 2993 - Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ-2993-Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- POJ-2993-Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh
- poj 2993 Emag eht htiw Em Pleh(关联2996)
- Android中EventBus使用详解(一)
- java中常用的快捷键
- 第四周项目5:程序分析
- 人生第一次全马
- C语言中的特殊转义字符
- poj-2993-Emag eht htiw Em Pleh && poj-2996-Help Me with the Game
- Spring中的@Autowired依赖注入
- b+c 模式 H5 与 Android 混合 开发详解
- 构建高并发高可用的电商平台架构实践
- STL与泛型编程<十二>:Stream(流)迭代器
- 初学的c语言一些简单的练习题(自我练习)
- 写mapreduce时的注意点
- 相似度算法
- JSTL