Download code

Jump to: navigation, search

Back to SavingUniverse_(Java)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

input.nw

 1 <<SavingUniverse.java>>==
 2 <<imports>>
 3 <<SavingUniverse class>>
 4 
 5 @ text
 6 
 7 <<imports>>=
 8 import java.io.*;
 9 import java.util.*;
10 @ text
11 
12 @ text
13 
14 <<Furthest Engine Method>>=
15  static int furthest( Set<String> engines , List<String> queries ) {
16   int furthest = 0;
17   for ( String engine : engines ) {
18    int distance;
19    distance=queries.indexOf(engine);
20    if (distance == -1 ) {
21     // Special case. If no match for this engine, it's the furthest.
22     return queries.size();
23    } else if ( distance > furthest ) {
24     furthest = distance;
25    }
26   }
27   return furthest;
28  }
29 @ text
30 
31 <<Required Switches Method>>=
32  static int requiredswitches ( Set<String> engines , List<String> queries ) {
33   int switches=-1;
34   int delbefore;
35   do {
36    delbefore = furthest(engines, queries);
37    System.err.println("Furthest engine is at: " + delbefore );
38    for (int delcount=1; delcount <= delbefore ; delcount++ ) {
39     System.err.println("Deleting item: " + queries.get(0) );
40     queries.remove(0);
41    }
42    switches++;
43   } while ( queries.size() != 0 );
44   return switches;
45  }
46 @ text
47 
48 <<Main Method>>=
49  public static void main(String args[]) throws IOException {
50   int cases;
51   int switches;
52   String aline;
53   String [] parts;
54 
55 
56   cases = Integer.parseInt(stdin.readLine());
57   for ( int currentCase=1 ; currentCase <= cases ; currentCase++ ) {
58    int engineLines;
59    int queryLines;
60    Set<String> engines = new HashSet<String>();
61    List<String> queries = new Vector<String>();
62    // Load engines
63    engineLines = Integer.parseInt(stdin.readLine());
64    for ( int currentEngine=1 ; currentEngine <= engineLines ; currentEngine++ ) {
65     aline = stdin.readLine();
66     engines.add(aline);
67     System.err.println("Adding engine: " + aline);
68    }
69    // Load queries
70    queryLines = Integer.parseInt(stdin.readLine());
71    for ( int currentQuery=1 ; currentQuery <= queryLines; currentQuery++ ) {
72     aline = stdin.readLine();
73     queries.add(aline);
74     System.err.println("Adding query: " + aline);
75    }
76    System.out.println("Case #" + currentCase + ": " +
77      requiredswitches(engines, queries));
78   }
79 
80  }
81 
82 @ text
83 


hijacker
hijacker
hijacker
hijacker

noweb.log

1 input.nw:1: unescaped << in documentation chunk
2 input.nw:2: unescaped << in documentation chunk
3 input.nw:3: unescaped << in documentation chunk