POJ 2996 Help Me with the Game 模拟法

http://poj.org/problem?id=2996

 

仔细读题 理解输出要求

和2993 相反

 

注意white 和 black的 坐标顺序 

  1 #include<stdio.h>

  2 #include<stdlib.h>

  3 #include<string.h>

  4 

  5 char str[17][33];

  6 int main()

  7 {

  8     char c;

  9     int i,j,h,flag=0,len,count;

 10     int nump=0,numP=0;

 11     for(i=0;i<17;i++)

 12     {

 13         scanf("%s",str[i]);

 14         len=strlen(str[i]);

 15         for(j=0;j<len;j++)

 16         {

 17             if(str[i][j]=='p')

 18             nump++;

 19             else if(str[i][j]=='P')

 20             numP++;

 21         }

 22     }

 23     count=1;

 24     printf("White: ");

 25     for(h=1;h<=5;h++)

 26     {

 27         flag++;

 28         if(flag==1)

 29         c='K';

 30         else if(flag==2)

 31         c='Q';

 32         else if(flag==3)

 33         c='R';

 34         else if(flag==4)

 35         c='B';

 36         else if(flag==5)

 37         c='N';

 38         for(i=1;i<=15;i+=2)

 39         {

 40             for(j=2;j<=30;j+=4)

 41             {

 42                 if(str[i][j]==c)

 43                 {

 44                     if(numP>0)

 45                     {

 46                         printf("%c",c);

 47                         printf("%c%c,",(j-2)/4+'a',(17-i)/2+'0');

 48                     }

 49                 else

 50                 {

 51                     printf("%c",c);

 52                     if(count==1)

 53                     {

 54                         printf("%c%c",(j-2)/4+'a',(17-i)/2+'0');count++;

 55                     }

 56                     else

 57                     printf(",%c%c",(j-2)/4+'a',(17-i)/2+'0');

 58                 }

 59                 }

 60             }

 61         }

 62     }

 63     c='P';

 64     flag=1;

 65     for(i=15;i>=1;i-=2)

 66     for(j=2;j<=30;j+=4)

 67     {

 68         if(str[i][j]==c)

 69         {    flag++;

 70         if(flag==2)

 71             printf("%c%c",(j-2)/4+'a',(17-i)/2+'0');

 72             else

 73              printf(",%c%c",(j-2)/4+'a',(17-i)/2+'0');

 74 

 75         }

 76     }

 77     flag=0;

 78     count=1;

 79     printf("\nBlack: ");

 80     for(h=1;h<=5;h++)

 81     {

 82         flag++;

 83         if(flag==1)

 84         c='K'+32;

 85         else if(flag==2)

 86         c='Q'+32;

 87         else if(flag==3)

 88         c='R'+32;

 89         else if(flag==4)

 90         c='B'+32;

 91         else if(flag==5)

 92         c='N'+32;

 93         for(i=1;i<=15;i+=2)

 94         {

 95             for(j=2;j<=30;j+=4)

 96             {

 97                 if(str[i][j]==c)

 98                 {

 99                     if(nump>0)

100                     {

101                         printf("%c",c-32);

102                         printf("%c%c,",(j-2)/4+'a',(17-i)/2+'0');

103                     }

104                     else

105                     {

106                          printf("%c",c-32);

107                         if(count==1)

108                         {printf("%c%c",(j-2)/4+'a',(17-i)/2+'0');

109                         count++;}

110                         else

111                         printf(",%c%c",(j-2)/4+'a',(17-i)/2+'0');

112                     }

113                 }

114             }

115         }

116     }

117     c='p';

118     flag=1;

119     for(i=1;i<=15;i+=2)

120     for(j=2;j<=30;j+=4)

121     {

122         if(str[i][j]==c)

123         {    flag++;

124         if(flag==2)

125             printf("%c%c",(j-2)/4+'a',(17-i)/2+'0');

126             else

127              printf(",%c%c",(j-2)/4+'a',(17-i)/2+'0');

128 

129         }

130     }

131     printf("\n");

132 

133 }
View Code

 

你可能感兴趣的:(with)