This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusacotools.java
More file actions
151 lines (137 loc) · 3.58 KB
/
Copy pathusacotools.java
File metadata and controls
151 lines (137 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.util.*;
import java.io.*;
public abstract class usacotools {
public static int ERROR=1;
public static String error="Error";
public static boolean isrect(int[][] map,int x,int y) {
int cachedsize=-1;
int cachey=-1;
for(int i=x;i<map.length;i++) {
if(x>cachedsize) {
return false;
}
for(int j=y;j<map.length;j++) {
if(map[x][y]==0) {
cachey=y;
cachedsize=x;
}
if(y>cachey) {
return false;
}
}
}
return true;
}
public static ArrayList<Integer> touching(int[][] map,int x,int y){
ArrayList<Integer> out=new ArrayList<Integer>();
try {
out.add(map[x-1][y]);
}catch(Exception e) {
}
try {
out.add(map[x+1][y]);
}catch(Exception e) {
}
try {
out.add(map[x][y-1]);
}catch(Exception e) {
}
try {
out.add(map[x][y+1]);
}catch(Exception e) {
}
return out;
}
public static String repeat(int count, String with) {
return new String(new char[count]).replace("\0", with);
}
public static String changen(int position, char ch, String str){
char[] charArray = str.toCharArray();
charArray[position] = ch;
return new String(charArray);
}
public static BufferedReader mreader(String filen) throws IOException {
return new BufferedReader(new FileReader(filen));
}
public static PrintWriter mwriter(String filen) throws IOException {
return new PrintWriter(new BufferedWriter(new FileWriter(filen)));
}
public static Scanner getsysscan() {
return new Scanner(System.in);
}
public static int binarySearch(int arr[], int l, int r, int x)
{
/*
* Binary Search
*
*/
if (r>=l)
{
int mid = l + (r - l)/2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid-1, x);
return binarySearch(arr, mid+1, r, x);
}
return -1;
}
public static int ebs(int arr[], int l, int r, int x) {
Arrays.sort(arr);
return binarySearch(arr, l, r, x);
}
public static int lsearch(int[] a,int b) {
for(int i=0;i<a.length;i++) {
if(a[i]==b) {
return i;
}
}
return -1;
}
public static void print(String out) {
System.out.print(out+"\n");
}
public static void printf(String out) {
System.out.print(out+"\n");
}
public static void print(String out,String end) {
System.out.print(out+end);
}
public static void print(String out,boolean flush) {
System.out.print(out+"\n");
if(flush) {
System.out.flush();
}
}
public static int[] toArray(ArrayList<Integer> arr) {
int[] stuff=new int[arr.size()];
for(int i=0;i<arr.size();i++) {
stuff[i]=arr.get(i);
}
return stuff;
}
public static String[] toArrays(ArrayList<String> arr) {
String[] stuff=new String[arr.size()];
for(int i=0;i<arr.size();i++) {
stuff[i]=arr.get(i);
}
return stuff;
}
public static Set<String> sclones(Set<String> k) {
return (new HashSet<String>(k));
}
public static Set<Integer> sclone(Set<Integer> k) {
return (new HashSet<Integer>(k));
}
public static void main(String[] args) throws Exception{
System.out.println("Running demo");
Scanner sc=getsysscan();
print("Welcome to the demo\nYou have many choices \n 1} Run help \n2} Check for a update \n3}Run demo to see features");
print(">","");
try {
int val=sc.nextInt();
}catch(Exception e) {
print("Oops that did not go well please rerun and choose a INTEGER");
}
}
}