GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/leftout.java at master · javaarchive/Java
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Expand file tree/ Copy pathleftout.javaMore file actions 213 lines (210 loc) · 5.13 KB / Copy pathleftout.javaFile metadata and controls213 lines (210 loc) · 5.13 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 import java.io.*; import java.util.*; public class leftout { public static boolean[][] photo; public static void printAsInt(boolean[][] photo) { /* for (int i = 0; i < photo.length; i++) { boolean[] sub = photo[i]; for (int j = 0; j < sub.length; j++) { boolean state = sub[j]; System.out.print(state ? 0:1); System.out.print(" "); } System.out.println(); } System.out.println(); */ } public static int sumArray() { int total = 0; for (int i = 0; i < photo.length; i++) { boolean[] row = photo[i]; for (int j = 0; j < row.length; j++) { boolean k = row[j]; if(!k) { total++; } } } return total; } public static int sumArray(int x1, int y1,int x2,int y2, boolean state) { int total = 0; for (int i = x1; i <= x2; i++) { boolean[] row = photo[i]; for (int j = y1; j <= y2; j++) { boolean k = row[j]; if(k == state) { total++; } } } return total; } public static boolean checkForTrue() { //int total = 0; for (int i = 0; i < photo.length; i++) { boolean[] row = photo[i]; for (int j = 0; j < row.length; j++) { boolean k = row[j]; if(!k) { return true; } } } return false; } public static boolean checkForTrue(int x,int y) { //int total = 0; for (int i = 1; i <= x; i++) { boolean[] row = photo[i]; for (int j = 1; j <= y; j++) { boolean k = row[j]; if(k) { return true; } } } return false; } public static boolean checkForFalse(int x,int y) { //int total = 0; for (int i = 1; i <= x; i++) { boolean[] row = photo[i]; for (int j = 1; j <= y; j++) { boolean k = row[j]; if(!k) { return true; } } } return false; } public static void flipRow(int row) { for(int i = 0; i < photo[row].length; i ++) { photo[row][i] = !(photo[row][i]); } } public static void flipCol(int col) { for(int i = 0; i < photo.length; i ++) { photo[i][col] = !(photo[i][col]); } } public static void main(String[] args) throws IOException{ BufferedReader f = new BufferedReader(new FileReader("leftout.in")); final int N = Integer.parseInt(f.readLine()); photo = new boolean[N][N]; for(int i = 0; i < N; i++) { String row = f.readLine(); for(int j = 0; j < N; j ++) { char c = row.charAt(j); if(c == 'L') { photo[i][j] = true; }else if(c == 'R') { photo[i][j] = false; } } } printAsInt(photo); /* // Used to be N for(int i = 0; i < N; i ++) { if(!photo[i][0]) { flipRow(i); } } printAsInt(photo); for(int i = 0; i < N; i ++) { if(!photo[0][i]) { flipCol(i); } }*/ for (int i=1; i<N; i++) { photo[i][0] = photo[i][0] ^ photo[0][0]; for (int j=1; j<N; j++) photo[i][j] = photo[i][j] ^ photo[0][j] ^ photo[i][0]; } printAsInt(photo); f.close(); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("leftout.out"))); int sa = sumArray(0,0,N-1,N-1,true); // Old condition sa == 0 || sa == N*N -1 if(false) { //System.out.println("Stop! Sum of whole is "); pw.println("-1"); }else { /* //boolean not_found = true; for(int i = 1; i < N; i ++) { for(int j = 1; j < N; j ++) { //System.out.println(checkForTrue(i,j)); if(checkForTrue(i,j)) { pw.println(i+" "+j); pw.close(); System.exit(0); //not_found = false; } } }for(int i = 1; i < N; i ++) { for(int j = 1; j < N; j ++) { //System.out.println(checkForTrue(i,j)); if(checkForFalse(i,j)) { pw.println(i+" "+j); pw.close(); System.exit(0); //not_found = false; } } } */ /* System.out.println("====Launching Debug===="); for(int i = 1; i < N ; i ++) { for(int j = 1; j < N; j ++) { System.out.println("--------Debug--------"); System.out.println(); System.out.println("True: "); System.out.println(i+" "+j+" SUM: "+sumArray(1, 1, i, j, true)); System.out.println("False: "); System.out.println(i+" "+j+" SUM: "+sumArray(1, 1, i, j, false)); } } */ if (sumArray(1,1,N-1,N-1,false) == 0) { pw.println("1 1"); pw.close(); System.exit(0); } if (sumArray(1,1,N-1,N-1,true) == N-1) { for (int j=1; j<N; j++) { if (sumArray(1,j,N-1,j,true)==N-1) { pw.println("1 " + (j+1)); pw.close(); System.exit(0); } } for (int i=1; i<N; i++) { if (sumArray(i,1,i,N-1,true)==N-1) { pw.println( (i+1) + " 1"); pw.close(); System.exit(0); } } System.out.println("-1 1st"); pw.println("-1\n"); pw.close(); System.exit(0); } if (sumArray(1,1,N-1,N-1,true)!=1) { System.out.println("-1 2nd"); pw.println("-1"); pw.close(); System.exit(0); } for (int i=1; i<N; i++) for (int j=1; j<N; j++) if (photo[i][j]==true) { pw.println((i+1) + " " + (j+1)); } } pw.close(); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |