POJ 2993 Emag eht htiw Em Pleh(模拟)

题目链接

只要理解了题意之后,就不是很难了。学长们,把题意讲的很明白了。:和.交替出现,坐标系是按平常数学上的坐标系建法。居然1Y了,意外。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <cmath>

 4 using namespace std;

 5 char p[101][101];

 6 void judge(char *s1,char *s2)

 7 {

 8     int i,len1,len2;

 9     len1 = strlen(s1);

10     len2 = strlen(s2);

11     for(i = 0; i <= len1-1; i ++)

12     {

13         if(s1[i] == ' '||s1[i] == ',')

14         {

15             if(s1[i+1] >= 'a'&&s1[i+1] <= 'h')

16             {

17                 p[s1[i+1]-'a'+1][s1[i+2]-'0'] = 'P';

18             }

19             else

20             {

21                 p[s1[i+2]-'a'+1][s1[i+3]-'0'] = s1[i+1];

22             }

23         }

24     }

25     for(i = 0; i <= len2-1; i ++)

26     {

27         if(s2[i] == ' '||s2[i] == ',')

28         {

29             if(s2[i+1] >= 'a'&&s2[i+1] <= 'h')

30             {

31                 p[s2[i+1]-'a'+1][s2[i+2]-'0'] = 'p';

32             }

33             else

34             {

35                 p[s2[i+2]-'a'+1][s2[i+3]-'0'] = s2[i+1]+'a'-'A';

36             }

37         }

38     }

39 }

40 int main()

41 {

42     int i,j;

43     char s1[101],s2[101];

44     gets(s1);

45     gets(s2);

46     if(s1[0] == 'W')

47     {

48         judge(s1,s2);

49     }

50     else

51     {

52         judge(s2,s1);

53     }

54     printf("+---+---+---+---+---+---+---+---+\n");

55     for(j = 8;j >= 1;j --)

56     {

57         printf("|");

58         for(i = 1;i <= 8;i ++)

59         {

60             if((i+j)%2)

61             {

62                 if(!p[i][j])

63                 {

64                     printf("...");

65                 }

66                 else

67                 {

68                     printf(".%c.",p[i][j]);

69                 }

70             }

71             else

72             {

73                  if(!p[i][j])

74                 {

75                     printf(":::");

76                 }

77                 else

78                 {

79                     printf(":%c:",p[i][j]);

80                 }

81             }

82             printf("|");

83         }

84         printf("\n+---+---+---+---+---+---+---+---+\n");

85     }

86     return 0;

87 }

你可能感兴趣的:(poj)