Исходный файл Substitution.java:
class Substitution {
static final int MAX_SIZE = 1024;
int siz;
int num[];
public Substitution() {
siz = 0;
num = new int[MAX_SIZE-1];
}
public Substitution(int size, int numbers[]) {
siz = size;
int i,j;
num = new int[MAX_SIZE-1];
int newSize = java.lang.reflect.Array.getLength(numbers);
boolean isOk = true;
for(i=0; i < newSize; i++) for(j=i + 1; j < newSize; j++) if((numbers[i] == numbers[j]) || (numbers[i] > size) || (numbers[i] < 1)) isOk = false;
if(isOk)
for (i=0; i < newSize; i++)
num[i] = numbers[i];
else
System.out.println("This is not a substitution!");
}
public int size() { return siz; }
public int map(int i) { return num[i]; }
public Substitution multiply (Substitution s) {
if(siz != s.size()) {
System.out.println("They are of different size!");
return new Substitution();
} else {
int newNumbers[] = new int[siz];
int i;
for(i=1; i <= siz; i++)
newNumbers[i-1] = s.map(num[i-1]-1);
return new Substitution(siz, newNumbers);
}
}
public Substitution inverse() {
int newNumbers[] = new int[siz];
int i,j;
for(i=1; i <= siz; i++) for(j=1; j <= siz; j++) if(num[j-1] == i) newNumbers[i-1] = j;
return new Substitution(siz, newNumbers);
}
}