POJ-2993 Emag eht htiw Em Pleh---棋盘模拟

题目链接:

https://vjudge.net/problem/POJ-2993

题目大意:

输入和输出和这里相反。

思路:

模拟题,没啥算法,直接模拟,不过为了代码精简,还是花了一点心思的

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<queue>
 7 #include<stack>
 8 #include<map>
 9 #include<sstream>
10 using namespace std;
11 typedef long long ll;
12 const int maxn = 1e2 + 10;
13 const int INF = 1 << 30;
14 int dir[4][2] = {1,0,0,1,-1,0,0,-1};
15 int T, n, m, x;
16 char Map[40][40];
17 void init()//将棋盘初始化
18 {
19     for(int i = 0; i < 17; i++)
20     {
21         if(i & 1)
22         {
23             for(int j = 0; j < 33; j ++)
24             {
25                 if(j % 4 == 0)Map[i][j] = ‘|‘;
26                 else if(((i / 2) & 1) == ((j / 4) & 1))Map[i][j] = ‘.‘;//这波操作好好理解,为了代码精简想出来的
27                 else Map[i][j] = ‘:‘;
28             }
29         }
30         else for(int j = 0; j < 33; j++)
31             if(j % 4 == 0)Map[i][j] = ‘+‘;
32             else Map[i][j] = ‘-‘;
33     }
34 }
35 void output()//输出棋盘
36 {
37     for(int i = 0; i < 17; i++)
38     {
39         for(int j = 0; j < 33; j++)
40         {
41             cout<<Map[i][j];
42         }
43         cout<<endl;
44     }
45 }
46 void solve(int d)
47 //x表示偏移量,白色的时候调用solve(0),黑色调用solve(32)
48 //表示每个大写字母加上32变成小写字母
49 {
50     string s;
51     getline(cin, s);
52     for(int i = 0; i < s.size(); i++)
53     {
54         if(s[i] == ‘:‘ || s[i] == ‘,‘)s[i] = ‘ ‘;
55     }
56     stringstream ss(s);
57     string s1;
58     while(ss >> s1)
59     {
60         int x, y;
61         if(s1.size() == 2)
62         {
63             x = s1[1] - ‘0‘;
64             y = s1[0] - ‘a‘;
65             x = 17 - x * 2;//将行数转化成具体在数组里面的行数
66             y = y * 4 + 2;//将列数转化成具体的列数
67             Map[x][y] = ‘P‘ + d;//这里加上d
68         }
69         else if(s1.size() == 3)
70         {
71             x = s1[2] - ‘0‘;
72             y = s1[1] - ‘a‘;
73             x = 17 - x * 2;
74             y = y * 4 + 2;
75             Map[x][y] = s1[0] + d;
76         }
77     }
78 }
79 int main()
80 {
81     init();
82     solve(0);
83     solve(‘a‘ - ‘A‘);
84     output();
85     return 0;
86 }

原文地址:https://www.cnblogs.com/fzl194/p/8719205.html

时间: 2024-10-12 19:44:09

POJ-2993 Emag eht htiw Em Pleh---棋盘模拟的相关文章

POJ 2993 Emag eht htiw Em Pleh (模拟)(strtok 应用)

http://www.zhuke.com/user/zkuser48082492?1r7R=123.baidu.com&eu=&lvhttp://www.zhuke.com/user/zkuser74628816?1r7R=123.baidu.com&eu=&lvhttp://www.zhuke.com/user/zkuser8162521?1r7R=123.baidu.com&eu=&lvhttp://www.zhuke.com/user/zkuser67

Poj 2993 Emag eht htiw Em Pleh

1.Link: http://poj.org/problem?id=2993 2.Content: Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2801   Accepted: 1861 Description This problem is a reverse case of the problem 2996. You are given the output of the

快速切题 poj 2993 Emag eht htiw Em Pleh 模拟

Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted: 1865 Description This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the correspond

POJ 2993 Emag eht htiw Em Pleh 模拟

http://poj.org/problem?id=2993 模拟大法好. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 char q[10],w[100]; 6 char e[10],r[100]; 7 char white[12]= {'K','Q','R','B','N','P'}; 8 char black[12]= {'k','q','r

模拟 + 打表 --- Emag eht htiw Em Pleh

Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2578   Accepted: 1731 Description This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the correspond

POJ2993——Emag eht htiw Em Pleh

Emag eht htiw Em Pleh DescriptionThis problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.Inputaccording to output of problem 2996.Outputaccording to input of probl

Emag eht htiw Em Pleh(imitate)

Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2901   Accepted: 1917 Description This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the correspond

poj2993(Emag eht htiw Em Pleh)

题目大意: 给你白棋子的位置: White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4和黑棋子的位置:Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6模拟出棋盘的情况a-h代表横坐标,1-17代表纵坐标.后面的位置首歌字符没有大写字母的是P,其中白棋子p是大写,黑棋子p是小写.解题思路:一句话太恶心,模拟一小时,我都晕了.代码: 1 #include <algorit

poj 2993

跟poj 2996反过来了,这里比较麻烦的就是处理白棋和黑棋各棋子对应的位置 还有在最后打印棋盘式|,:,.的时候会有点繁琐(- - ACMer新手 ): 直接看代码吧: 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 char white[10][10],black[10][10]; 6 char s[]={"+---+---+---+-