#include using namespace std; bool isNeighbourNum(int n) { while (n != 0) { if (n % 10 == (n / 10) % 10) return false; n /= 10; } return true; } int subNeighbours(int a, int b) { int smallest = 0, biggest = 0; for (int i = a; i <= b; i++) { if (isNeighbourNum(i)) { if (i < smallest || !smallest) smallest = i; if (i > biggest || !biggest) biggest = i; } } if (!smallest || !biggest) { return -1; } return biggest - smallest; } int main() { cout << "a = "; int a; cin >> a; cout << "b = "; int b; cin >> b; int sub = subNeighbours(a, b); if (sub == -1) cout << "No adjacent numbers!" << endl; else cout << sub << endl; }