POJ 2996 Help Me with the Game && POJ 2993 Emag eht htiw Em Pleh

解题思路:普通模拟题


POJ 2996 Help Me with the Game

1 #include<iostream>
2 #include <map>
3  using namespace std;
4
5 struct Point{char y, x;};
6
7 int main()
8 {
9 char chess[17][34];
10 char key[][6] = {{'K', 'Q', 'R', 'B', 'N', 'P'}, {'k', 'q', 'r', 'b', 'n', 'p'}};
11
12 multimap<char, Point >letter;
13 multimap<char, Point>::iterator iter1, iter2;
14 Point point;
15
16 for (int i = 16; i >= 0; i--)
17 cin >> chess[i];
18
19 for (int i = 1; i < 9; i++)
20 {
21 for (int j = 1; j < 9; j++)
22 {
23 point.y = i + '0', point.x = j - 1 + 'a';
24 if (chess[i * 2 - 1][j * 4 - 2] < 'Z')
25 letter.insert(make_pair(chess[i * 2 - 1][j * 4 - 2], point));
26 point.y = 9 - i + '0', point.x = j - 1 + 'a';
27 if (chess[17 - i * 2][j * 4 - 2] > 'a')
28 letter.insert(make_pair(chess[17 - i * 2][j * 4 - 2], point));
29 }
30 }
31 for (int j = 0; j < 2; j++)
32 {
33 bool first = true;
34 for (int i = 0; i < 6; i++)
35 {
36 iter1 = letter.lower_bound(key[j][i]);
37 iter2 = letter.upper_bound(key[j][i]);
38 while (iter1 != iter2)
39 {
40 if (first)
41 {
42 cout << ((j == 0 ? "White: " : "Black: "));
43 first = false;
44 }
45 else
46 cout << ",";
47 if(i < 5)
48 cout << char((j == 0) ? key[j][i] : (key[j][i] + 'A' - 'a'));
49 cout << (iter1->second).x <<(iter1->second).y;
50 iter1++;
51 }
52 }
53 if (!first)
54 cout << endl;
55 }
56
57 return 0;
58 }

POJ 2993 Emag eht htiw Em Pleh

1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5 int main()
6 {
7 char chess[8][8] = {0}, ch;
8 int row, col;
9 string str;
10 for(int i = 0; i < 2; i++)
11 {
12 getline(cin, str);
13 if (str[0] == 'B')i++;
14
15 for(int j = 0; j < str.length(); j++)
16 {
17 if (str[j] == ',' || str[j] == ' ')
18 {
19 if(str[++j] >= 'a')
20 {
21 ch = ((i == 0) ? 'P' : 'p');
22 col = str[j] - 'a';
23 }
24 else
25 {
26 ch = (i == 0) ? str[j] : (str[j] - 'A' + 'a');
27 col = str[++j] - 'a';
28 }
29 row = str[++j] - '1';
30 chess[7 - row][col] = ch;
31 }
32 }
33 }
34 for (int i = 0; i < 8; i++)
35 {
36 cout << "+---+---+---+---+---+---+---+---+" << endl;
37 for (int j = 0; j < 8; j++)
38 {
39 cout << '|';
40 cout << (((i + j) % 2 == 0) ? '.' : ':');
41 if (chess[i][j] == 0)
42 cout << (((i + j) % 2 == 0) ? '.' : ':');
43 else
44 cout << chess[i][j];
45 cout << (((i + j) % 2 == 0) ? '.' : ':');
46 }
47 cout << "|" << endl;
48 }
49 cout << "+---+---+---+---+---+---+---+---+" << endl;
50
51 return 0;
52 }

 

posted on 2010-11-01 20:02  ltang  阅读(210)  评论(0)    收藏  举报

导航