题目链接:
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