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

这个题以前做过一遍。。当时居然没写博客。。这题其实也算不上模拟吧,我只是用了几套公式。。


#include <stdio.h>
#include <string.h>
char map[50][50];
int main()
{
    char s1[200], s2[200];
    int i, j, len1, len2, x, y;
    for(i=0;i<17;i++)
    {
        for(j=0;j<33;j++)
        {
            if(i%2==0&&j%4==0)
                map[i][j]='+';
            else if(i%2==0)
                map[i][j]='-';
            else if(j%4==0)
                map[i][j]='|';
            else if(((j/4)%2&&(i/2)%2)||((j/4)%2==0&&(i/2)%2==0))
                map[i][j]='.';
            else
                map[i][j]=':';
        }
    }
    gets(s1);
    len1=strlen(s1);
    for(i=7;i<len1;i++)
    {
        if(s1[i]>='A'&&s1[i]<='Z')
        {
            map[(8-s1[i+2]+'0')*2+1][(s1[i+1]-'a')*4+2]=s1[i];
            i+=3;
        }
        else if(s1[i]>='a'&&s1[i]<='z')
        {
            map[(8-s1[i+1]+'0')*2+1][(s1[i]-'a')*4+2]='P';
            i+=2;
        }
    }
    gets(s2);
    len2=strlen(s2);
    for(i=7;i<len2;i++)
    {
        if(s2[i]>='A'&&s2[i]<='Z')
        {
            map[(8-s2[i+2]+'0')*2+1][(s2[i+1]-'a')*4+2]=s2[i]+32;
            i+=3;
        }
        else if(s2[i]>='a'&&s2[i]<='z')
        {
            map[(8-s2[i+1]+'0')*2+1][(s2[i]-'a')*4+2]='p';
            i+=2;
        }
    }
    for(i=0;i<17;i++)
    {
        for(j=0;j<33;j++)
        {
            printf("%c",map[i][j]);
        }
        printf("\n");
    }
    return 0;
}