HLOJ_1194

 1  // 1194  Accepted  0 176 697 C++  
 2  #include  < stdio.h >
 3 
 4  int  tnum ;
 5  char  data[ 10 ] ;
 6 
 7  bool  isin(  int  x,  int  y )
 8  {
 9       if ( x  >=   1   &&  x  <=   8   &&  y <= 8   &&  y >= 1  )
10           return   true  ;
11       else
12           return   false  ;
13  }
14  int  main()
15  {
16       while ( scanf(  " %d " & tnum )  !=  EOF )
17      {
18           while ( tnum  --  )
19          {
20              scanf(  " %s " , data ) ;
21               int  x  =  data[ 0 -   ' a '   +   1  ;
22               int  y  =  data[ 1 -   ' 1 '   +   1  ;
23 
24               int  cnt  =   0  ;
25               if ( isin( x + 1 , y + 2  ) ) cnt ++  ;
26               if ( isin( x - 1 , y + 2  ) ) cnt ++  ;
27               if ( isin( x + 2 , y + 1  ) ) cnt ++  ;
28               if ( isin( x - 2 , y + 1  ) ) cnt ++  ;
29 
30               if ( isin( x + 1 , y - 2  ) ) cnt ++  ;
31               if ( isin( x - 1 , y - 2  ) ) cnt ++  ;
32               if ( isin( x + 2 , y - 1  ) ) cnt ++  ;
33               if ( isin( x - 2 , y - 1  ) ) cnt ++  ;
34 
35              printf(  " %d\n " , cnt ) ;
36          }
37      }
38       return   0  ;
39  }

你可能感兴趣的:(HLOJ_1194)