1OK = false ;
2while(!OK) {
3 in();
4 int t = n-1;
5 while(a[t] > a[t+1]) t--;
6 if(t) {
7 int i = n;
8 while(a[i] < a[t]) i--;
9 swap(a[i],a[t]);
10 int l = t+1, r= n;
11 while(l<r) {
12 swap(a[l],a[r]);
13 l++; r--;
14 }
15 } else OK = true;
16}