implement load all
authorDralagen <dralagen@dralagen.fr>
Thu, 7 Nov 2013 14:15:15 +0000 (15:15 +0100)
committerDralagen <dralagen@dralagen.fr>
Thu, 7 Nov 2013 14:15:15 +0000 (15:15 +0100)
src/Prog.java

index 747b5a8..9ff0524 100644 (file)
@@ -1,5 +1,5 @@
-import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.util.ArrayList;
 import java.util.Scanner;
 
 
@@ -43,17 +43,45 @@ public class Prog
        public static Permutation load() {
                return load(1);
        }
-       public static Permutation[] loadAll()
+       public static ArrayList<Permutation> loadAll()
        {
-               Permutation[] p = new Permutation[5];
+               ArrayList<Permutation> p = new ArrayList<Permutation>();
+               try
+               {
+                       int n;
+                       int elts[];
+                       Scanner sc = new Scanner(new FileReader(pathPermutation));
+                       while (sc.hasNextLine()) {
+                               if (sc.hasNextInt()){
+                                       n = sc.nextInt();
+                                       elts = new int[n];
+                                       String buff;
+                                       for (int i = 0; i < n ; i++)
+                                       {
+                                               buff = sc.next();
+                                               buff = buff.replace(")","");
+                                               buff = buff.replace("(","");
+                                               elts[i] = Integer.parseInt(buff);
+                                       }
+                                       p.add(new Permutation(n,elts));
+                               }
+                               sc.nextLine();
+                       }
+                       sc.close();
+               } catch (Exception e)
+               {
+                       e.printStackTrace();
+               }
                return p;
        }
 
        public static void main(String[] args)
        {
-               Permutation p = load(4);
-               System.out.println(p.eltsToString());
-               p.chercherMin();
-               System.out.println(p.minsToString());
+               ArrayList<Permutation> p = loadAll();
+               for (int i = 0; i < p.size(); ++i){
+                       System.out.println(p.get(i).eltsToString());
+                       p.get(i).chercherMin();
+                       System.out.println(p.get(i).minsToString());
+               }
        }
 }