1-
1+ /*
2+ * USACOTOOLS-Official version
3+ * This is the official version.
4+ *
5+ */
26import java .util .*;
37import java .io .*;
48public abstract class usacotools {
@@ -16,6 +20,11 @@ public abstract class usacotools {
1620 public static String error ="Error" ;
1721 public static int debugcode =-1 ;
1822 public static boolean DEBUG =false ;
23+ public static boolean lock ;
24+ public static boolean IO =true ;
25+ public static void blockio () {
26+ IO =false ;
27+ }
1928 public static boolean isrect (int [][] map ,int x ,int y ) {
2029 int cachedsize =-1 ;
2130 int cachey =-1 ;
@@ -105,6 +114,7 @@ public static String changen(int position, char ch, String str){
105114 return new String (charArray );
106115 }
107116 public static BufferedReader mreader (String filen ) throws IOException {
117+ //Make a reader
108118 return new BufferedReader (new FileReader (filen ));
109119 }
110120 public static PrintWriter mwriter (String filen ) throws IOException {
@@ -137,6 +147,7 @@ public static int binarySearch(int arr[], int l, int r, int x)
137147 return -1 ;
138148 }
139149 public static int [][] copy2D (int [][] a ){
150+ if (!(lock )) {return null ;}
140151 int [][] b =new int [a .length ][];
141152 for (int i =0 ;i <a .length ;i ++) {
142153 b [i ]=new int [a [i ].length ];
@@ -147,6 +158,7 @@ public static int[][] copy2D(int[][] a){
147158 return b ;
148159 }
149160 public static int [] copyarr (int [] a ) {
161+ if (!(lock )) {return null ;}
150162 int [] b =new int [a .length ];
151163
152164 for (int i =0 ;i <a .length ;i ++) {
@@ -155,10 +167,12 @@ public static int[] copyarr(int[] a) {
155167 return b ;
156168 }
157169 public static int ebs (int arr [], int l , int r , int x ) {
170+
158171 Arrays .sort (arr );
159172 return binarySearch (arr , l , r , x );
160173 }
161174 public static int lsearch (int [] a ,int b ) {
175+
162176 for (int i =0 ;i <a .length ;i ++) {
163177 if (a [i ]==b ) {
164178 return i ;
@@ -167,6 +181,7 @@ public static int lsearch(int[] a,int b) {
167181 return -1 ;
168182 }
169183 public static void print (String out ) {
184+
170185 System .out .print (out +"\n " );
171186 }
172187 public static void printf (String out ) {
@@ -182,6 +197,7 @@ public static void print(String out,boolean flush) {
182197 }
183198 }
184199 public static int [] toArray (ArrayList <Integer > arr ) {
200+ if (!(lock )) {return null ;}
185201 int [] stuff =new int [arr .size ()];
186202 for (int i =0 ;i <arr .size ();i ++) {
187203 stuff [i ]=arr .get (i );
@@ -190,6 +206,7 @@ public static int[] toArray(ArrayList<Integer> arr) {
190206
191207 }
192208 public static String [] toArrays (ArrayList <String > arr ) {
209+ if (!(lock )) {return null ;}
193210 String [] stuff =new String [arr .size ()];
194211 for (int i =0 ;i <arr .size ();i ++) {
195212 stuff [i ]=arr .get (i );
@@ -210,6 +227,7 @@ public static long benchmark2() {
210227 return System .nanoTime ();
211228 }
212229 public static void clear (){
230+
213231 //Clears Screen in java
214232 try {
215233 if (System .getProperty ("os.name" ).contains ("Windows" ))
@@ -309,6 +327,7 @@ public static int classify(char x,char off,char on) {
309327
310328 }
311329 public static long slowfib (long num ){
330+ //Slow recursion fibonnaci
312331 if (num <=1 ) {
313332 return num ;
314333 }
@@ -317,6 +336,9 @@ public static long slowfib(long num){
317336 }
318337 public static ArrayList <Long > fibmem =new ArrayList <Long >();
319338 public static long ffib (long n ){
339+ /*
340+ * Fibonnaci implemented with DP
341+ */
320342 if (n <=1 ) {
321343 return n ;
322344 }
@@ -335,6 +357,7 @@ public static void setupfib() {
335357 fibmem .add ((long ) 0 );fibmem .add ((long )1 );fibmem .add ((long )1 );fibmem .add ((long )2 );
336358 }
337359 public static void show2Darr (int [][] a ) {
360+ //Print out a 2D array for you
338361 for (int [] b :a ) {
339362 for (int c :b ) {
340363 print (c +" " ,"" );
@@ -344,6 +367,7 @@ public static void show2Darr(int[][] a) {
344367 }
345368 }
346369 public static void showarr (int [] a ) {
370+ //Print out a array for you
347371 for (int x :a ) {print (x +" " );}
348372 }
349373 public static int [][] dpcache ;
@@ -366,62 +390,39 @@ public static int ks(int W,int[] wt,int[] val,int n) {
366390 public static void kssetup (int n ,int W ) {
367391 dpcache =new int [n +1 ][W +1 ];
368392 }
369- public static void main ( String [] args ) throws Exception {
393+ public static int count ( int [] arr ) {
370394 /*
371- * Short demo of stuff
372- * Making an error would also demo error reporting
373- *
395+ * Number of groups of 1s
396+ * Modify for other purposes if needed
397+ * Example
398+ * 1111000111
399+ * Returns 2
374400 *
375401 */
376- System .out .println ("Running demo" );
377- Scanner sc =getsysscan ();
378- print ("Welcome to the demo" );
379- print (">" ,"" );
380- int val ;
381- /*
382- int[][] testarray= {
383- {1,1,2,7,7,1,1,1},
384- {1,1,4,0,7,1,2,2},
385- {0,3,6,9,1,0,0,0},
386- {0,3,0,1,0,0,0,0},
387- {0,3,0,0,0,0,0,0},
388- {1,1,5,1,3,1,1,1},
389- {1,1,1,1,3,1,1,1},
390- };
391- */
392- int [][] testarray = {
393- {1 ,2 ,3 ,1 },
394- {4 ,5 ,6 ,2 },
395- {7 ,8 ,9 ,3 },
396- {10 ,69 ,1 ,4 }
397-
398- };
399- print ("Roation of 90 degrees\n Before \n " );
400- show2Darr (testarray );
401- print ("After \n " );
402- show2Darr (rotate90cw (testarray ));
403- print ("BEFORE:" );
404- int [][] ii = {
405- {1 ,1 ,2 ,3 },
406- {1 ,0 ,2 ,1 },
407- {1 ,1 ,1 ,1 },
408- {1 ,2 ,3 ,4 }
409- };
410- show2Darr (ii );
411- print ("After H reflect:" );
412- show2Darr (reverseh (ii ));
413-
414- try {
415- val =sc .nextInt ();
416- }catch (Exception e ) {
417- print ("Oops that did not go well please rerun and choose a INTEGER" );
418- val =-1 ;
419- report (e );
420- print ("How about we test error reporting" );
421- console ();
422- }
423- if (1 ==val ) {
424-
402+ boolean b =false ;int c =0 ;int temp ;
403+ for (int i =0 ;i <arr .length ;i ++) {
404+ temp =arr [i ];
405+ if (temp ==0 && b ) {
406+ b =false ;
407+ c ++;
408+ }
409+ if (temp ==1 && b ==false ) {
410+ b =true ;
411+ }
425412 }
413+ return c ;
414+ }
415+ private static boolean _lock =false ;
416+ public static void NOLOCK () {
417+ _lock =true ;
418+ }
419+ public static void LOCK () {
420+ if (!(_lock )) {lock =true ;}
421+ }
422+ public static void UNLOCK () {
423+ if (!(_lock )) {lock =false ;}
424+ }
425+ public static void main (String [] args ) throws Exception {
426+ print ("the demo has been removed do to lack of support. Instead we display info about the library." );
426427 }
427428}
0 commit comments