poj2996 Help Me with the Game

 1 /*    poj2996
 2  *    id:    symons
 3  *    memory 700k
 4  *    time   0ms
 5  */
 6 #include <iostream>
 7 #include <string>
 8 #include <algorithm>
 9 #include <stdio.h>
10 using namespace std;
11 
12 string gird[17];
13 
14 void output_white(char aim)
15 {
16     int l=gird[0].length();
17 
18     for(int i=16;i>=0;--i)
19     {
20         for(int j=0;j<l;++j)
21         {
22             if(gird[i][j]==aim)
23             {
24                 char temp;
25                 temp=j/4+'a';
26                 if(aim=='K')
27                     cout<<aim<<temp<<(16-i)/2+1;
28                 else if(aim=='P')
29                     cout<<","<<temp<<(16-i)/2+1;
30                 else 
31                     cout<<","<<aim<<temp<<(16-i)/2+1;
32             }
33         }
34     }
35     return ;
36 }
37 void output_black(char aim)
38 {
39     int l=gird[0].length();
40 
41     for(int i=0;i<17;++i)
42     {
43         for(int j=0;j<l;++j)
44         {
45             if(gird[i][j]==aim)
46             {
47                 char temp;
48                 char change;
49                 change=aim-'a'+'A';
50                 temp=j/4+'a';
51                 if(aim=='k')
52                     cout<<change<<temp<<(16-i)/2+1;
53                 else if(aim=='p')
54                     cout<<","<<temp<<(16-i)/2+1;
55                 else
56                     cout<<","<<change<<temp<<(16-i)/2+1;
57             }
58         }
59     }
60     return ;
61 }
62 
63 int main()
64 {
65     while(cin>>gird[0])
66     {
67         for(int i=1;i<=16;++i)
68         {
69             cin>>gird[i];
70         }
71         cout<<"White: ";
72         output_white('K');
73         output_white('Q');
74         output_white('R');
75         output_white('B');
76         output_white('N');
77         output_white('P');
78         cout<<endl;
79         cout<<"Black: ";
80         output_black('k');
81         output_black('q');
82         output_black('r');
83         output_black('b');
84         output_black('n');
85         output_black('p');
86         cout<<endl;
87     }
88     return 0;
89 }
90 
91         
原文地址:https://www.cnblogs.com/symons1992/p/3015861.html