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[]={"+---+---+---+---+---+---+---+---+"};
 7 int main()
 8 {
 9     memset(white,‘0‘,sizeof(white));
10     memset(black,‘0‘,sizeof(black));
11     char x[50],y[50];
12     gets(x);
13     for(int i=0;i<strlen(x);++i){
14         if((x[i]==‘K‘||x[i]==‘Q‘||x[i]==‘R‘||x[i]==‘B‘||x[i]==‘N‘)&&i>5)
15             white[x[i+2]-‘0‘][x[i+1]-‘a‘+1]=x[i],i+=3;
16         if((x[i]>=‘a‘&&x[i]<=‘h‘)&&i>5)
17             white[x[i+1]-‘0‘][x[i]-‘a‘+1]=‘P‘,i+=2;
18     }
19     gets(y);
20     for(int i=0;i<strlen(y);++i){
21         if((y[i]==‘K‘||y[i]==‘Q‘||y[i]==‘R‘||y[i]==‘B‘||y[i]==‘N‘)&&i>5)
22             black[y[i+2]-‘0‘][y[i+1]-‘a‘+1]=y[i]-‘A‘+‘a‘,i+=3;
23         if((y[i]>=‘a‘&&y[i]<=‘h‘)&&i>5)
24             black[y[i+1]-‘0‘][y[i]-‘a‘+1]=‘p‘,i+=2;
25     }
26     cout << s << endl;
27     for(int i=8;i>0;--i){
28         cout << "|";
29         for(int j=1;j<=8;++j){
30             if(i%2==0){
31                 if(j%2==1){
32                     cout << ".";
33                 if(white[i][j]!=‘0‘)    cout << white[i][j] << ".|";
34                 else if(black[i][j]!=‘0‘)    cout << black[i][j] << ".|";
35                 else    cout << "..|";
36                 }
37                 else if(j%2==0){
38                     cout << ":";
39                     if(white[i][j]!=‘0‘)    cout << white[i][j] << ":|";
40                     else if(black[i][j]!=‘0‘)    cout << black[i][j] << ":|";
41                     else    cout << "::|";
42                 }
43             }
44             else{
45                     if(j%2==1){
46                         cout << ":";
47                     if(white[i][j]!=‘0‘)    cout << white[i][j] << ":|";
48                     else if(black[i][j]!=‘0‘)    cout << black[i][j] << ":|";
49                     else    cout << "::|";
50                     }
51                     else{
52                         cout << ".";
53                         if(white[i][j]!=‘0‘)    cout << white[i][j] << ".|";
54                         else if(black[i][j]!=‘0‘)    cout << black[i][j] << ".|";
55                         else    cout << "..|";
56                     }
57             }
58         }
59         cout << endl << s << endl;
60     }
61 } 
时间: 2024-10-12 13:35:20

poj 2993的相关文章

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

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 (模拟)(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 模拟

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题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递

POJ 刷题指南

OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递推. 构造法.(POJ 3295) 模拟法.(POJ 1068,POJ 2632,POJ 1573,POJ 2993,POJ 2996) 二

POJ 2996 &amp; 2993 国际象棋布局 模拟

Description Your task is to read a picture of a chessboard position and print it in the chess notation. Input The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white pl

【转】POJ题目分类

初级:基本算法:枚举:1753 2965贪心:1328 2109 2586构造:3295模拟:1068 2632 1573 2993 2996图:最短路径:1860 3259 1062 2253 1125 2240最小生成树:1789 2485 1258 3026拓扑排序:1094二分图的最大匹配:3041 3020最大流的增广路算法:1459 3436数据结构:串:1035 3080 1936排序:2388 2299哈希表和二分查找等高效查找法:3349 3274 2151 1840 2002

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&