sinh hoan vi c++
OK = false ;
while(!OK) {
in();
int t = n-1;
while(a[t] > a[t+1]) t--;
if(t) {
int i = n;
while(a[i] < a[t]) i--;
swap(a[i],a[t]);
int l = t+1, r= n;
while(l<r) {
swap(a[l],a[r]);
l++; r--;
}
} else OK = true;
}