Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <conio.h>
- using namespace std;
- int main() {
- string s;
- bool error = false;
- bool ok = false;
- getline(cin, s);
- vector<char> c(5);
- if (s.length() == 5) {
- for (int i = 0; i < 5; i++) {
- c[i] = s[i];
- }
- }
- else error = true;
- if (error == false) {
- if (c[0] < 65 || c[0] > 72) error = true;
- else if (c[1] < 49 || c[1] > 56) error = true;
- else if (c[2] != 45) error = true;
- else if (c[3] < 65 || c[0] > 72) error = true;
- else if (c[4] < 49 || c[4] > 56) error = true;
- }
- if (error == false) {
- if (abs(c[0] - c[3]) == 1 && abs(c[1] - c[4]) == 2) ok = true;
- else if (abs(c[0] - c[3]) == 2 && abs(c[1] - c[4]) == 1) ok = true;
- }
- if (error == false) {
- if (ok == true) cout << "YES";
- else cout << "NO";
- }
- else cout << "ERROR";
- _getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment