开发者

iteration on numbers with no 2 same digits

开发者 https://www.devze.com 2022-12-25 06:57 出处:网络
I dont know if it is asked (I couldn\'t find any). I want to iterate on this kind of numbers implemented on array;

I dont know if it is asked (I couldn't find any).

I want to iterate on this kind of numbers implemented on array;

int a[10];
int i = 0;
for( ; i < 10; i++ )
    a[i] = i+1;

now the array has

"1 2 3 4 5 6 7 8 9 10"

and I want to get

"1 2 3 4 5 6 7 8 10 9"

and then

"1 2 3 4 5 6 7 9 8 10"

"1 2 3 4 5 6 7 9 10 8"

. . . .

I tried to get an algorithm but I couldn't figure it out. Is there an easy 开发者_运维技巧way to implement "next" iterator for this kind of problems?

Thanks in advance


Check std::next_permutation.

0

精彩评论

暂无评论...
验证码 换一张
取 消