对于两个整数a,b,如果b是严格大于a且各位数字均不相同的最小整数

对于两个整数a,b,如果b是严格大于a且各位数字均不相同的最小整数
输入
一个整数a,1000≤a≤90001000≤a≤9000。

输出
一个整数b,题目保证有解。

#include <iostream>
using namespace std;
int func(int n)
{
int a = n % 10;
int b = (n / 10) % 10;
int c = (n / 100) % 10;
int d = (n / 1000) % 10;
return a != b && b != c && c != d && a !=c && b != d && a != d;
}
int main()
{
int a, b;
cin >> a;
b = a + 1;
while (!func(b)) b++;
cout << b << endl;
return 0;
}