模拟 POJ 2993 Emag eht htiw Em Pleh

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

 /*
题意:与POJ2996完全相反
模拟题 + 字符串处理:无算法,读入两行字符串找出相应点用used标记,输出时标记过的输出字母,否则输出'.'或':'。
注意:棋盘的行的顺序是从下到上递增的
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int used[MAXN][MAXN];
char a[MAXN][MAXN];
map<char, int> m;
string s1,s2; void print(int tw, int tb)
{
bool flag = false;
for (int i=; i<=; ++i)
{
cout << "+---+---+---+---+---+---+---+---+" << endl;
cout << "|";
flag = !flag;
for (int j=; j<=; ++j)
{
(flag) ? cout << "." : cout << ":";
if (!used[i][j]) (flag) ? cout << "." : cout << ":";
else
{
cout << a[i][j];
}
(flag) ? cout << "." : cout << ":";
flag = !flag;
cout << "|";
}
cout << endl;
} cout << "+---+---+---+---+---+---+---+---+" << endl;
} void work(void)
{
int tw = , tb = ;
for (int i=; s1[i]!='\0'; ++i) //White
{
if (s1[i] == ',') continue;
if (s1[i]<='S' && s1[i] >= 'B')
{
a[-(s1[i+]-'')][m[s1[i+]]] = s1[i];
used[-(s1[i+]-'')][m[s1[i+]]] = ;
i += ;
}
if (s1[i]<='s' && s1[i]>='a')
{
a[-(s1[i+]-'')][m[s1[i]]] = 'P';
used[-(s1[i+]-'')][m[s1[i]]] = ;
i += ;
}
if (i >= s1.size ()) break;
}
for (int i=; s2[i]!='\0'; ++i) //Black
{
if (s2[i] == ',') continue;
if (s2[i]<='S' && s2[i] >= 'B')
{
a[-(s2[i+]-'')][m[s2[i+]]] = s2[i] - 'A' + 'a';
used[-(s2[i+]-'')][m[s2[i+]]] = ;
i += ;
}
if (s2[i]<='s' && s2[i]>='a')
{
a[-(s2[i+]-'')][m[s2[i]]] = 'p';
used[-(s2[i+]-'')][m[s2[i]]] = ;
i += ;
}
if (i >= s2.size ()) break;
} print (tw, tb);
} int main(void) //POJ 2993 Emag eht htiw Em Pleh
{
//freopen ("J.in", "r", stdin); char ch = 'a';
for (int i=; i<=; ++i)
{
m[ch++] = i;
} getline (cin, s1);
getline (cin, s2);
memset (used, , sizeof (used));
work (); return ;
} /*
+---+---+---+---+---+---+---+---+
*/ /*
+---+---+---+---+---+---+---+---+
|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|
+---+---+---+---+---+---+---+---+
|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|
+---+---+---+---+---+---+---+---+
|...|:::|.n.|:::|...|:::|...|:p:|
+---+---+---+---+---+---+---+---+
|:::|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|...|:::|...|:::|.P.|:::|...|:::|
+---+---+---+---+---+---+---+---+
|:P:|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|
+---+---+---+---+---+---+---+---+
|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|
+---+---+---+---+---+---+---+---+
*/
上一篇:C++ 中利用 Opencv 得到不规则的ROI 区域(已知不规则区域)


下一篇:if处理多分支结构