fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6. string cell;
  7. cin>>cell;
  8. if((cell.size()==5) &&
  9. (((cell[0]>='A' && cell[0]<='H') || (cell[0]>='a' && cell[0]<='h')) && //x1
  10. (cell[1]>='1' && cell[1]<='8')) && //y1
  11. (cell[2]=='-') && //-
  12. (((cell[3]>='A' && cell[3]<='H') || (cell[3]>='a' && cell[3]<='h')) && //x2
  13. (cell[4]>='1' && cell[4]<='8'))) //y2
  14. {
  15. int x1 = tolower(cell[0]) - 'a' + 1;
  16. int y1 = cell[1] - '0';
  17. int x2 = tolower(cell[3]) - 'a' + 1;
  18. int y2 = cell[4] - '0';
  19. if(x1==x2 && y1==y2)
  20. cout<<"ERROR";
  21. else if( ((abs(x1 - x2)==1) && (abs(y1 - y2)==2)) ||
  22. ((abs(x1 - x2)==2) && (abs(y1 - y2)==1)) )
  23. cout<<"YES";
  24. else
  25. cout<<"NO";
  26. }
  27. else
  28. cout<<"ERROR";
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
ERROR