题目:点击打开链接
模拟题,和POJ2996恰好题意相反,通过所给案例基本上没有啥问题了。。。
下面AC代码:
#include <stdio.h>
#include <string.h>
struct node
{
char ch;
int col;//列号a-h;
int row;//行号1-8
}white[65],black[65];
int main()
{
char s[1000];
int len,len1,len2,i,j;
char a[100][100];
int flag;
gets(s);
len=strlen(s);
len1=len2=0;
for(i=0;i<len;)
{
if(s[i]==' ' || s[i]==',')
{
j=i+1;
while(s[j]!=',' && j<len) j++;
if(j-i==4)
{
white[len1].ch=s[i+1];
white[len1].col=(s[i+2]-'a')*4+2;
white[len1].row=('8'-s[i+3]+1)*2-1;
}
else if(j-i==3)
{
white[len1].ch='P';
white[len1].col=(s[i+1]-'a')*4+2;
white[len1].row=('8'-s[i+2]+1)*2-1;//行号
}
len1++;
i=j;
}
else i++;
}
gets(s);
len=strlen(s);
for(i=0;i<len;)
{
if(s[i]==' ' || s[i]==',')
{
j=i+1;
while(s[j]!=',' && j<len) j++;
if(j-i==4)
{
black[len2].ch=s[i+1]+32;
black[len2].col=(s[i+2]-'a')*4+2;
black[len2].row=('8'-s[i+3]+1)*2-1;
}
else if(j-i==3)
{
black[len2].ch='p';
black[len2].col=(s[i+1]-'a')*4+2;
black[len2].row=('8'-s[i+2]+1)*2-1;
}
len2++;
i=j;
}
else i++;
}
flag=1;
for(i=0;i<17;i++)
{
if(i%2==0)
strcpy(a[i],"+---+---+---+---+---+---+---+---+");
else
{
for(j=0;j<33;)
if(j%4==0) {a[i][j]='|';j++;}
else
{
if(flag==1)
{a[i][j]='.';a[i][j+1]='.';a[i][j+2]='.';j+=3;flag=0;}
else
{a[i][j]=':';a[i][j+1]=':';a[i][j+2]=':';j+=3;flag=1;}
}
a[i][j]='\0';
if(flag==0) flag=1;
else flag=0;
}
}
for(i=0;i<len1;i++)
a[black[i].row][black[i].col]=black[i].ch;
for(i=0;i<len2;i++)
a[white[i].row][white[i].col]=white[i].ch;
for(i=0;i<17;i++)
{
printf("%s\n",a[i]);
}
return 0;
}