daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string s;
  10.     bool error = false;
  11.     bool ok = false;
  12.     getline(cin, s);
  13.  
  14.     vector<char> c(5);
  15.     if (s.length() == 5) {
  16.         for (int i = 0; i < 5; i++) {
  17.             c[i] = s[i];
  18.         }
  19.     }
  20.     else error = true;
  21.  
  22.     if (error == false) {
  23.         if (c[0] < 65 || c[0] > 72) error = true;
  24.         else if (c[1] < 49 || c[1] > 56) error = true;
  25.         else if (c[2] != 45) error = true;
  26.         else if (c[3] < 65 || c[0] > 72) error = true;
  27.         else if (c[4] < 49 || c[4] > 56) error = true;
  28.     }
  29.  
  30.     if (error == false) {
  31.         if (abs(c[0] - c[3]) == 1 && abs(c[1] - c[4]) == 2) ok = true;
  32.         else if (abs(c[0] - c[3]) == 2 && abs(c[1] - c[4]) == 1) ok = true;
  33.     }
  34.  
  35.     if (error == false) {
  36.         if (ok == true) cout << "YES";
  37.         else cout << "NO";
  38.     }
  39.     else cout << "ERROR";
  40.  
  41.     _getch();
  42.     return 0;
  43. }
RAW Paste Data
Top