/*
* Created on Oct 22, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author WangBNU
* helloquota@163.com
* My Homepage http://bnulinux.yeah.net
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PaiLie {
public static void main(String args[]) {
int leng = args[0].length();
int[] a = new int[leng];
boolean[] c = new boolean[leng];
for (int i = 0; i < leng; i++) {
a[i] = i + 1;
c[i] = false;
}
int ii = findActiveM(a, c);
for (int i = 0; i < args[0].length(); i++)
System.out.print(a[i]);
System.out.println( ) ;
if (ii >= 0) {
do {
int activeM= a[ii] ;
if (c[ii] == false) {
swapInt(a,ii, ii - 1);
swapBoolean(c,ii, ii - 1);
} else {
swapInt(a,ii, ii + 1);
swapBoolean(c,ii, ii + 1);
}
for (int i = 0; i < args[0].length(); i++) {
System.out.print(a[i]);
if (a[i] > activeM)
c[i] = !c[i];
}
System.out.println();
ii = findActiveM(a, c);
} while (ii >= 0);
}
}
/**
* @param aa
* @param a
* @param b
*/
private static void swapInt(int[] aa , int a, int b) {
int temp = aa[a];
aa[a] = aa[b];
aa[b] = temp;
}
private static void swapBoolean(boolean[] aa , int a , int b) {
boolean temp = aa[a];
aa[a] = aa[b];
aa[b] = temp;
}
private static int findActiveM(int[] a, boolean[] c) {
int first1 = 0, first2 = 0;
int m = -1, n = -1;
for (int i = 1; i < a.length - 1; i++) {
if (c[i] == false) {
if ((a[i] > a[i - 1]) && a[i] > first1) {
first1 = a[i];
m = i;
}
} else {
if ((a[i] > a[i + 1]) && a[i] > first2) {
first2 = a[i];
n = i;
}
}
}
if ((c[0] == true) && (a[0] > a[1]) && (a[0] > first2)) {
first2 = a[0];
n = 0;
}
if ((c[a.length - 1] == false) && (a.length>1)
&& (a[a.length - 1] > a[a.length - 2])
&& (a[a.length - 1] > first1)) {
first1 = a[a.length - 1];
m = a.length - 1;
}
if (first1 >= first2)
return m;
else
return n;
}
}
* Created on Oct 22, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author WangBNU
* helloquota@163.com
* My Homepage http://bnulinux.yeah.net
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PaiLie {
public static void main(String args[]) {
int leng = args[0].length();
int[] a = new int[leng];
boolean[] c = new boolean[leng];
for (int i = 0; i < leng; i++) {
a[i] = i + 1;
c[i] = false;
}
int ii = findActiveM(a, c);
for (int i = 0; i < args[0].length(); i++)
System.out.print(a[i]);
System.out.println( ) ;
if (ii >= 0) {
do {
int activeM= a[ii] ;
if (c[ii] == false) {
swapInt(a,ii, ii - 1);
swapBoolean(c,ii, ii - 1);
} else {
swapInt(a,ii, ii + 1);
swapBoolean(c,ii, ii + 1);
}
for (int i = 0; i < args[0].length(); i++) {
System.out.print(a[i]);
if (a[i] > activeM)
c[i] = !c[i];
}
System.out.println();
ii = findActiveM(a, c);
} while (ii >= 0);
}
}
/**
* @param aa
* @param a
* @param b
*/
private static void swapInt(int[] aa , int a, int b) {
int temp = aa[a];
aa[a] = aa[b];
aa[b] = temp;
}
private static void swapBoolean(boolean[] aa , int a , int b) {
boolean temp = aa[a];
aa[a] = aa[b];
aa[b] = temp;
}
private static int findActiveM(int[] a, boolean[] c) {
int first1 = 0, first2 = 0;
int m = -1, n = -1;
for (int i = 1; i < a.length - 1; i++) {
if (c[i] == false) {
if ((a[i] > a[i - 1]) && a[i] > first1) {
first1 = a[i];
m = i;
}
} else {
if ((a[i] > a[i + 1]) && a[i] > first2) {
first2 = a[i];
n = i;
}
}
}
if ((c[0] == true) && (a[0] > a[1]) && (a[0] > first2)) {
first2 = a[0];
n = 0;
}
if ((c[a.length - 1] == false) && (a.length>1)
&& (a[a.length - 1] > a[a.length - 2])
&& (a[a.length - 1] > first1)) {
first1 = a[a.length - 1];
m = a.length - 1;
}
if (first1 >= first2)
return m;
else
return n;
}
}