Advertisement
dllbridge

Untitled

Dec 19th, 2022
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1.  
  2. //  Запросить с клавиатуры строку, содержащую координаты двух клеток шахматной доски.
  3. //  Указать одного они цвета или нет.
  4.  
  5.  
  6. #include   <stdio.h>
  7.  
  8.  
  9. char     sz1[17],
  10.          sz2[2][7] = {"black", "white"};
  11.  
  12.  
  13. int      nArr[5],
  14.            i = 0,
  15.          x1,  x2,  //  Цвет (0 или 1) первой и второй клеток
  16.          pos = 0;
  17.  
  18.  
  19. ////////////////////////////////////////////////////
  20. int main()                                        //
  21. {
  22.    
  23.     printf("Enter the coordinates of 2 cells.");
  24.     printf("  For example: E2-E4, e2-e4, E2E4, e2e4.\n");
  25.      
  26.     scanf("%s", sz1);
  27.    
  28.     while(sz1[i])
  29.     {
  30.        
  31.         if(sz1[i] > '0')  nArr[pos++] = sz1[i] % 2;
  32.  
  33.         if(pos == 4) break;
  34.        
  35.         i++;
  36.     }
  37.    
  38.     if(pos < 4)
  39.     {
  40.        printf("Error! You entered the coordinates incorrectly.\n");
  41.        printf("You entered: %s\n", sz1);
  42.        return 0;
  43.     }
  44.     x1 = (nArr[0] + nArr[1]) % 2;  
  45.     x2 = (nArr[2] + nArr[3]) % 2;
  46.    
  47.     if(x1 == x2) printf("Yes, same colors.  \n");
  48.     else         printf("No, various colors.\n");
  49.    
  50.     printf("1st cell is %s \n", sz2[x1]);
  51.     printf("2nd cell is %s \n", sz2[x2]);  
  52. }
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement