UVa 630 kept getting wrong answer [closed] - java

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I have been working on the UVa 630 problem for 2 days, http://acm.uva.es/p/v6/630.html
I have written a working code, however constantly getting the wrong answer result after the submission, my program works fine for the given input format and generate correct result, could someone please take a look at my code and find what's wrong with it please.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
class Main {
String[] init;
String[] sorted;
int voca = 0;
String[] test;
private String x;
private String y;
ArrayList<ArrayList> initial = new ArrayList<ArrayList>();
char[] charArray;
String input;
void initSort(String i) {
input = i;
charArray = input.toCharArray();
}
char[] get() {
return charArray;
}
void sort(int low, int high) {
int i = low;
char pivot = charArray[low];
for (int j = low + 1; j < high; j++) {
if (charArray[j] < pivot) {
if (j > i + 1) {
exchange(i + 1, j);
}
i++;
}
}
exchange(low, i);
if (i > low + 1)
sort(low, i);
if (i + 2 < high)
sort(i + 1, high);
}
void exchange(int i, int j) {
char temp = charArray[i];
charArray[i] = charArray[j];
charArray[j] = temp;
}
// ********************************************
void begin() {
// System.out.println("begin test");
int numOfdataSet;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
numOfdataSet = Integer.parseInt(in.readLine());
do {
ArrayList currentSet = new ArrayList();
int numberOfdic;
String tempStringV;
String tempStringT;
int i = 0;
try {
String emptyLine = in.readLine();
numberOfdic = Integer.parseInt(in.readLine());
;
currentSet.add(emptyLine);
currentSet.add(Integer.toString(numberOfdic));
// System.out.println("enter numberOfdic is " +
// numberOfdic);
while (i < numberOfdic) {
tempStringV = in.readLine();
currentSet.add(tempStringV);
i++;
}
// System.out.println("input test word");
tempStringT = in.readLine();
currentSet.add(tempStringT);
while (!tempStringT.equals("END")) {
tempStringT = in.readLine();
currentSet.add(tempStringT);
}
} catch (IOException e) {
e.printStackTrace();
}
initial.add(currentSet);
numOfdataSet--;
} while (numOfdataSet != 0);
} catch (IOException e) {
}
;
print();
}
// ***************************************************
void getArrays(ArrayList<String> a) {
// read the file and put the words into a temporary array
String[] temp = new String[a.size()];
for (int i = 0; i < a.size(); i++) {
temp[i] = a.get(i);
// System.out.println("temp "+i+" is "+temp[i]);
}
// extract the vocabulary counter from the temp array
int vocaCounter;
int shift;
if (!temp[0].equals("")) {
shift = 2;
vocaCounter = Integer.parseInt(temp[1]);
} else {
shift = 2;
vocaCounter = Integer.parseInt(temp[1]);
}
// System.out.println("there are "+vocaCounter);
// store the vocabulary into the array named as init
init = new String[vocaCounter];
for (int i = shift; i < vocaCounter + shift; i++) {
init[i - shift] = temp[i];
// System.out.println(i - shift + " voca is " + init[i - shift]);
}
// store the test words into the array named as test
test = new String[temp.length - vocaCounter - shift - 1];
for (int j = 0; j < temp.length - vocaCounter - shift - 1; j++) {
test[j] = temp[j + vocaCounter + shift];
// System.out.println("test "+j+" is "+test[j]);
}
sorted = init;
}
/**
* sort the two strings
*/
void arraySorter() {
x = x.toLowerCase();
initSort(x);
sort(0, x.length());
get();
// java.util.Arrays.sort(FirstArray);
y = y.toLowerCase();
initSort(y);
sort(0, y.length());
get();
}
String getEle(String in) {
initSort(in);
sort(0, in.length());
return new String(get());
}
void print() {
Iterator<ArrayList> iterator = initial.iterator();
while (iterator.hasNext()) {
getArrays((ArrayList<String>) iterator.next());
// ****************
/**
* sort the test array and store it as the testSort array
*/
String[] testSort = new String[test.length];
for (int i = 0; i < test.length; i++) {
testSort[i] = test[i];
}
for (int i = 0; i < test.length; i++) {
testSort[i] = getEle(testSort[i]);
}
// for(int i=0;i<test.length;i++)
// {
// System.out.println("test is "+test[i]+" and test sorted is "+testSort[i]);
// }
/**
* sort the vocabulary array and store the sorted array as vocaSort
*/
String[] vocaSort = new String[init.length];
for (int i = 0; i < init.length; i++) {
vocaSort[i] = init[i];
}
for (int i = 0; i < init.length; i++) {
vocaSort[i] = getEle(vocaSort[i]);
}
// start the testing process
for (int i = 0; i < test.length; i++) {
int counter = 1;
System.out.println("Anagrams for: " + test[i]);
for (int j = 0; j < sorted.length; j++) {
// anagramTester(test[i], init[j]);
boolean result = testSort[i].equals(vocaSort[j]);// //AnagramTester();
if (result == true && counter < 10) {
System.out.println(" " + counter + ") " + init[j]);
counter++;
} else if (result == true && counter < 100) {
System.out.println(" " + counter + ") " + init[j]);
counter++;
} else if (result == true && counter < 1000) {
System.out.println("" + counter + ") " + init[j]);
counter++;
}
}
if (counter == 1)
System.out.println("No anagrams for: " + test[i]);
}
System.out.println();
}
}
/**
* main function
*
* #param args
*/
public static void main(String[] args) {
Main myWork = new Main(); // create a dinamic instance
myWork.begin();
}
}
below is the input.txt file
1
4
atol
lato
rola
tara
kola
tola
END
2
24
uhgj
uhjg
ughj
ugjh
ujhg
ujgh
hujg
hugj
hgju
hguj
hjgu
hjug
guhj
gujh
ghuj
ghju
gjuh
gjhu
jugh
juhg
jhgu
jhug
jghu
jguh
jguh
END

it was a output format issue and problem solved

Related

How to show 2 or more duplicates with this array using java?

i would like to display 2 or more duplicated customers using joptionpane. It is working if there is only 1 duplicate customer but unfortunately the message dialogue wasnt showing if there is 2 or more duplicated customer. Here is my code.
public static void main(String[] args) {
int number;
number = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of customers: "));
int[] one = new int[number];
int[] two = new int[number];
for (int i = 0; i < number; i++) {
one[i] = Integer.parseInt(JOptionPane.showInputDialog("Customer number: "));
}
int y = 0;
for (int i = 0; i < one.length - 1; i++) {
for (int w = i + 1; w < one.length; w++) {
if (one[i] == one[w]) {
two[y] = one[w];
y = y + 1;
break;
}
}
for (int p = 0; p < y - 1; p++) {
if (one[p] == two[p - 1]) {
y = y - 1;
break;
}
}
}
if (y == 0) {
JOptionPane.showMessageDialog(null, "\nHONEST CUSTOMERS");
} else if (y != 0) {
JOptionPane.showMessageDialog(null, "Duplicates:");
for (int o = 0; o < y; o++) {
JOptionPane.showMessageDialog(null, "Customer #" + two[o]);
//jop.showMessageDialog(null, "Duplicates: Customer #" + two[l]);
//}
}
}
}
}
How can i show the message dialogue if i want to show 2 or more duplicated customers? thank you for the help.
Break down your code into the following:
A function that takes the two lists and return a list of pairs of duplicates.
A function that takes the list of duplicates and create a string stating: "Duplicates: value1, value2..."
Show message box.
here is an solution for your problem using Collections:
public static Integer[] getDuplicates(Integer[] list) {
List<Integer> duplicates = new ArrayList<>(Arrays.asList(list));
Set<Integer> seen = new HashSet<>(Arrays.asList(list));
for (Integer i : seen) {
duplicates.remove(i);
}
Set<Integer> uniqueDuplicate = new HashSet<>(duplicates);
return uniqueDuplicate.toArray(Integer[]::new);
}
public static void main(String[] args) {
int number;
number = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of customers: "));
Integer[] one = new Integer[number];
for (int i = 0; i < number; i++) {
one[i] = Integer.parseInt(JOptionPane.showInputDialog("Customer number: "));
}
Integer[] two = getDuplicates(one);
if (two.length == 0) {
JOptionPane.showMessageDialog(null, "\nHONEST CUSTOMERS");
} else {
JOptionPane.showMessageDialog(null, "Duplicates:");
for (int o = 0; o < two.length; o++) {
JOptionPane.showMessageDialog(null, "Customer #" + two[o]);
// jop.showMessageDialog(null, "Duplicates: Customer #" + two[l]);
// }
}
}
}

Separate text in k-shingles without Scanner.class in Java

I am trying to separate a text in k-shingles, sadly I cannot use scanner. If the last shingle is too short, I want to fill up with "_". I came this far:
public class Projektarbeit {
public static void main(String[] args) {
testKShingling(7, "ddssggeezzfff");
}
public static void testKShingling(int k, String source) {
//first eliminate whitespace and then fill up with withespaces to match target.length%shingle.length() == 0
String txt = source.replaceAll("\\s", "");
//get shingles
ArrayList<String> shingles = new ArrayList<String>();
int i;
int l = txt.length();
String shingle = "";
if (k == 1) {
for(i = 0; i < l; i++){
shingle = txt.substring(i, i + k);
shingles.add(shingle);
};
}
else {
for(i = 0; i < l; i += k - 1){
try {
shingle = txt.substring(i, i + k);
shingles.add(shingle);
}
catch(Exception e) {
txt = txt.concat("_");
i -= k - 1;
};
};
}
System.out.println(shingles);
}
}
Output: [ddssgge, eezzfff, f______]
It works almost, but in the with the given parameters in the example the last shingle is not necessary (it should be [ddssgge, eezzfff]
Any idea how to do this more beautiful?
To make the code posted work you only need to add break and the end of the catch block:
catch(Exception e) {
txt = txt.concat("_");
i -= k - 1;
break;
};
Having said that I wouldn't use an Exception to control the program. Exception are just that: should be used for run time errors.
Avoid StringIndexOutOfBoundsException by controlling the loop parameters:
public static void main(String[] args) {
testKShingling(3, "ddssggeezzfff");
}
public static void testKShingling(int substringLength, String source) {
//todo validate input
String txt = source.replaceAll("\\s", "");
//get shingles
ArrayList<String> shingles = new ArrayList<>();
int stringLength = txt.length();
if (substringLength == 1) {
for(int index = 0; index < stringLength; index++){
String shingle = txt.substring(index, index + substringLength);
shingles.add(shingle);
};
}
else {
for(int index = 0; index < stringLength -1 ; index += substringLength - 1){
int endIndex = Math.min(index + substringLength, stringLength);
String shingle = txt.substring(index, endIndex);
if(shingle.length() < substringLength){
shingle = extend(shingle, substringLength);
}
shingles.add(shingle);
};
}
System.out.println(shingles);
}
private static String extend(String shingle, int toLength) {
String s = shingle;
for(int index = 0; index < toLength - shingle.length(); index ++){
s = s.concat("_");
}
return s;
}
An alternative implementation of testKShingling:
public static void testKShingling(int substringLength, String source) {
//todo validate input
String txt = source.replaceAll("\\s", "");
ArrayList<String> shingles = new ArrayList<>();
if (substringLength == 1) {
for(char c : txt.toCharArray()){
shingles.add(Character.toString(c));
};
}
else {
while(txt.length() > substringLength) {
String shingle = txt.substring(0, substringLength);
shingles.add(shingle);
txt = txt.substring(substringLength - 1); //remove first substringLength - 1 chars
}
if(txt.length() < substringLength){ //check the length of what's left
txt = extend(txt, substringLength);
}
shingles.add(txt); //add what's left
}
System.out.println(shingles);
}

Replacing a string parameter with a List for a recursive method

I was struggeling with a probably simple problem for the last 3 hours. I rewrote a class and replaced 2 String parameters with Lists.
The problem is, that when calling the rekursive method you add 1 character to the first string parameter. And when the length of the parameter hits the length of 7 it prints it out. The string never gets longer than 7.
I replaced it with a Integer List since the String only consisted of numbers.
The List though keeps getting longer and longer and I have no idea why. I hope I explained everything properly. If not, ask me please.
The question is probably super easy to answer for you guys.
Here is the first class, that works.
package Uebung4;
public class PermAll_Alt {
static int counter = 0;
private static void permutation(String word, String str) {
int n = str.length();
// System.out.println(str + " Str");
// System.out.println(word + " word");
if (n == 0) {
if (
(Integer.parseInt(word.substring(0, 1))) > (Integer.parseInt(word.substring(1, 2)))
&& (Integer.parseInt(word.substring(1, 2))) < (Integer.parseInt(word.substring(2, 3)))
&& (Integer.parseInt(word.substring(2, 3))) > (Integer.parseInt(word.substring(3, 4)))
&& (Integer.parseInt(word.substring(3, 4))) < (Integer.parseInt(word.substring(4, 5)))
&& (Integer.parseInt(word.substring(4, 5))) > (Integer.parseInt(word.substring(5, 6)))
&& (Integer.parseInt(word.substring(5, 6))) < (Integer.parseInt(word.substring(6, 7)))
) {
// System.out.println(word);
counter++;
}
} else {
for (int i = 0; i < n; i++) {
// System.out.println("Word: " +word+"\t str charat:
// "+str.charAt(i));
// System.out.println(word + str.charAt(i) + " \t combined");
System.out.println("substr(0,i): " + str.substring(0, i) + " substr(i+1) " + str.substring(i + 1));
permutation(word + str.charAt(i), str.substring(0, i) + str.substring(i + 1));
}
}
}
public static void main(String[] args) {
permutation("", "1234567");
System.out.println("Anzahl: " + counter);
}
}
And here is my class that I edited:
package Uebung4;
import java.util.ArrayList;
import java.util.List;
public class PermAll {
static int counter = 0;
private static void permutation(List<Integer> wordList, List<Integer> lis) {
// List<Integer> wordList2 = cloneList(wordList);
int n = lis.size();
if (n == 0) {
String word = "";
for (Integer i : wordList) {
word += i;
}
if ((Integer.parseInt(word.substring(0, 1))) > (Integer.parseInt(word.substring(1, 2)))
&& (Integer.parseInt(word.substring(1, 2))) < (Integer.parseInt(word.substring(2, 3)))
&& (Integer.parseInt(word.substring(2, 3))) > (Integer.parseInt(word.substring(3, 4)))
&& (Integer.parseInt(word.substring(3, 4))) < (Integer.parseInt(word.substring(4, 5)))
&& (Integer.parseInt(word.substring(4, 5))) > (Integer.parseInt(word.substring(5, 6)))
&& (Integer.parseInt(word.substring(5, 6))) < (Integer.parseInt(word.substring(6, 7)))
) {
System.out.println(word);
// convertToDU(word);
counter++;
}
} else {
for (int i = 0; i < n; i++) {
List<Integer> tempLis = new ArrayList<>();
//String tempString = "";
for (int j = 0; j < i; j++) {
tempLis.add(lis.get(j));
}
System.out.print("str.substr(0,i): " + tempLis+"\t");
for (int k = i + 1; k < lis.size(); k++) {
tempLis.add(lis.get(k));
System.out.print(""+lis.get(k)+", ");
}
System.out.println(tempLis);
// System.out.println("word "+wordList + "\t charat:
// "+lis.get(i));
wordList.add(lis.get(i));
// System.out.println(wordList + " \t kombiniert");
permutation(wordList, tempLis);
// permutation(word + lis.get(i),tempLis);
}
}
}
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
int anzahl = 7;
for (int i = 1; i <= anzahl; i++) {
list.add(i);
}
String para = "";
for (Integer i : list) {
para += i;
}
List<Integer> abc = new ArrayList<>();
permutation(abc, list);
System.out.println("Anzahl: " + counter);
}
}
Here is a solution: I took the code that was doing the recursive call in the String args version and copied the logic to the List args version:
for (int i = 0; i < n; i++) {
// create a copy of wordList
List<Integer> permWordList = new ArrayList<Integer>(wordList);
// equiv to "word + str.charAt(i)"
permWordList.add(strLis.get(i));
// create a copy of lis
List<Integer> permStrList = new ArrayList<Integer>(lis);
// equiv to "str.substring(0, i) + str.substring(i + 1)"
permStrList.remove(i);
permutation(permWordList, permStrList);
}

java sort string array according to kurdish characters

Is there any short way to sort a string array by Kurdish characters? I've looked at some source on internet but I couldn't find any solution. There is a way to sort. Writing a code alike a novel but it is a very long work.
kurdish characters: a,b,c,ç,d,e,ê,f,g,h,i,î,j,k,l,m,n,o,p,q,r,s,ş,t,û,u,v,w,x,y,z
The Collator class should come in-handy here. To quote from the doc,
The Collator class performs locale-sensitive String comparison. You use this class to build searching and sorting routines for natural language text.
So try something like this:
Collator unicodeCollator = Collator.getInstance(Locale.UNICODE_LOCALE_EXTENSION);
Collections.sort(yourListOfCharacters, unicodeCollator);
Note that we are able to call java.util.Collections.sort directly as above, because Collator implements the Comparator interface.
If for whatever reasons Locale.UNICODE_LOCALE_EXTENSION doesn't work, here's the full list of supported locales. And you can create your own locale using the Locale constructor.
I've solved my problem: content of my file was like this:
*Nîzamettîn Ariç - Kardeş Türküler - Rojek Tê
Bê xem bê şer welat azad rojek tê
Rojek ronahî rojek bişahî rojek tê
Roj Roja me ye....
*Koma Çiya - Tolhildan ^ Daketine Meydanê
Daketine meydanê gerilayên dînemêr
Ji bona tolhildanê wek baz û piling û şêr...
My solution: thîs letters is proper for toLowerCase function:
ABCÇDEÊFGĞHİÎJKLMNOÖPQRSŞTÛUÜVWXYZ
just I was problem. because lowerCase(I) for turkish is ı; but for kurdish it is i.
code:
in onCreate():
...
alfabetBike();
...
public static void alfabetBike() {
for (int i = 0; i < tips.length(); i++) {
String[] derbasi_arr = sernavs[i];
String[] derbasi_got = gotins[i];
for (int j = 0; j < hejmar[i] - 1; j++) {
int indeks = j;
String yaMezin = derbasi_arr[j];
for (int k = j + 1; k < hejmar[i]; k++) {
if (compareTwoString(yaMezin.substring(1), derbasi_arr[k].substring(1)) > 1) {
yaMezin = derbasi_arr[k];
indeks = k;
}
}
if (indeks != j) {
derbasi_arr[indeks] = derbasi_arr[j];
String derbasi = derbasi_got[indeks];
derbasi_got[indeks] = derbasi_got[j];
derbasi_arr[j] = yaMezin;
derbasi_got[j] = derbasi;
}
}
gotins[i] = derbasi_got;
sernavs[i] = derbasi_arr;
}
}
private static void printFile(){
alfabetBike();
File root = android.os.Environment.getExternalStorageDirectory();
File dir = new File (root.getAbsolutePath() + "/alfabetfolder");
dir.mkdirs();
File file = new File(dir, "alfabet_title.txt");
File file2 = new File(dir, "alfabet.txt");
try {
FileOutputStream f = new FileOutputStream(file,false);
PrintWriter pw = new PrintWriter(f);
FileOutputStream f2 = new FileOutputStream(file2,false);
PrintWriter pw2 = new PrintWriter(f2);
for (int i = 0; i < tips.length(); i++) {
for (int j = 0; j < hejmar[i]; j++) {
Log.d("ssdddddd", "add" + hejmar[i] + "-" + j + " " + sernavs[i][j].trim());
pw.println(sernavs[i][j]);
pw.flush();
pw2.println(sernavs[i][j] + "\n" + gotins[i][j].trim());
pw2.flush();
}
}
pw.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("erroooor", "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
} catch (IOException e) {
e.printStackTrace();
}
}
public static int compareTwoString(String yek, String du) {
String d1 = yek, d2 = du;
d1 = strLower(d1, d1.charAt(0));
d2 = strLower(d2, d2.charAt(0));
int length, yaDirej;
if (yek.length() > du.length()) {
yaDirej = 1;
length = yek.length();
} else if (yek.length() < du.length()) {
yaDirej = 2;
length = du.length();
} else {
yaDirej = 0;
length = yek.length();
}
for (int i = 0; i < length; i++) {
int id1 = -1, id2 = -1;
if (i == d1.length() || i == du.length()) {
return yaDirej;
}
for (int j = 0; j < tips.length(); j++) {
if (d1.charAt(i) == tips.charAt(j)) id1 = j;
if (d2.charAt(i) == tips.charAt(j)) id2 = j;
}
if (id1 > id2)
return 2;
else if (id2 > id1)
return 1;
else
continue;
}
return 0;
}
public static String strLower(String str, char ziman){
final StringBuilder mutable = new StringBuilder(str);
final StringBuilder yedek = new StringBuilder(str.toLowerCase());
for (int i = 0; i < str.length(); i++) {
if (ziman == '?' && mutable.charAt(i) == 'I')
mutable.setCharAt(i, 'i');
else if (ziman == '*' && mutable.charAt(i) == 'I')
mutable.setCharAt(i, 'ı');
else mutable.setCharAt(i,yedek.charAt(i));
}
return mutable.toString();
}
edit:
in AndroidManifest.xml
<manifest...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
....
</manifest...>
You can build your own comparison so that, no matter what characters you are dealing with, it is going to sort the way you want. As you can see from the following code, I have set the comparison value by counting from a-z so that a=0, b=1...etc Then, I used the bubble sort strategy, which is basically switching the smallest elements continuously to the left and shifting others to the right.
public class Sort {
public static String compare(String compare1, String compare2) {
for (int i = 0; i < compare1.length(); i++) {
if (letterValue(compare1, i) < letterValue(compare2, i)) {
return compare1;
} else if (letterValue(compare1, i) > letterValue(compare2, i)) {
return compare2;
} else if (letterValue(compare1, i) == -1 || letterValue(compare2, i) == -1) {
System.out.print("Some letters are not within the alphabet!");
}
}
return compare1;
}
public static boolean smaller(String compare1, String compare2) {
if (compare(compare1, compare2).equalsIgnoreCase(compare1)) {
return true;
} else {
return false;
}
}
public static int letterValue(String input, int letterPosition) {
String order = "abcçdeêfghiîjklmnopqrsştûuvwxyz";
int value = -1;
for (int i = 0; i < order.length(); i++) {
if (input.toLowerCase().charAt(letterPosition) == order.charAt(i)) {
value = i;
}
}
return value;
}
public static void main(String[] args) {
String[] input = {"BARÊZ", "ÇÊneR", "ASTÛ", "badîn", "BADÎN"};
String swap;
int i, d;
for (i = 0; i < (input.length - 1); i++) {
for (d = 0; d < input.length - i - 1; d++) {
if (!smaller(input[d], input[d + 1])) {
swap = input[d];
input[d] = input[d + 1];
input[d + 1] = swap;
}
}
}
System.out.println("Sorted list: ");
for (i = 0; i < input.length; i++) {
System.out.print(input[i] + " ");
}
}
}
Output
Sorted list:
ASTÛ badîn BADÎN BARÊZ ÇÊneR

java recurrsion with ArrayList not working

I am doing recursion for a given phone number and print all the possible string representation of the number. The problem is in loop for (int j=0;j<ops;j++) { the size of the "perm" ArrayList keep increasing in every iteration. I want to get fixed pattern and add new number e.g perm = 11 and call recursion with tperm=110,111,112.
import java.util.*;
public class phoneNum {
public static void getSt ( List<Integer>list , List<Integer> perm ) {
Integer len = list.size();
Integer len1 = perm.size();
Integer ops = 0;
if (len == len1) {
for(int k=0;k<len;k++) {
System.out.print(" " + list.get(k));
}
for(int k=0;k<len;k++) {
System.out.print(" " + perm.get(k));
}
System.out.print("====");
System.out.print(getPattrn(list,perm));
System.out.println("\n");
} else {
for (int i=0; i<len1+1; i++) {
if(list.get(i) == 7 || list.get(i) == 9) {
ops = 4;
} else {
ops = 3;
}
for (int j=0;j<ops;j++) {
List<Integer> tperm = new ArrayList<Integer>(perm);
tperm.add(i,j);
System.out.println("Size=" + tperm.size() + " ---" + perm.size());
getSt(list,tperm);
}
}
}
}
You can add tperm.remove(i) at the end of inner for loop.

Categories

Resources