Skip to content

Commit 93d64db

Browse files
committed
色々追加
1 parent 88624b1 commit 93d64db

20 files changed

+2430
-68
lines changed

.pydevproject

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
4+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
5+
</pydev_project>

analysis/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import requests
2+
r = requests.get('http://www.google.co.jp')
3+
print r.text

src/AlienAndGame.java

+38-68
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,39 @@ public int getNumber(String[] board) {
1111
table[i][j] = board[i].charAt(j) == 'W';
1212
}
1313
}
14-
int max = 0;
15-
for (int i = 0; i < table.length; i++) {
16-
for (int j = 0; j < table[0].length; j++) {
17-
int ret = minCellColumn(table, i, j);
18-
int ret2 = minCellRow(table, i, j);
19-
20-
max = Math.max(Math.max(ret, ret2), max);
21-
}
22-
}
23-
return max * max;
24-
}
25-
26-
private int minCellRow(boolean[][] table, int i, int j) {
27-
// ?????????????????????????????????
28-
int max = 0;
29-
for (int l = 0; l < 50; l++) {
30-
31-
for (int j2 = j; j2 < j + l && j2 < table[0].length; j2++) {
32-
int count = 0;
33-
for (int k = i; k < i + l && k < table.length; k++) {
34-
if (table[k][j2] == table[i][j2]) {
35-
count++;
36-
} else {
37-
break;
14+
for (int r = 50; r >= 0; r--) {
15+
for (int i = 0; i <= table.length - r; i++) {
16+
for (int j = 0; j <= table[0].length - r; j++) {
17+
boolean ret = checkRow(table, i, j, r);
18+
if (ret) {
19+
return r * r;
3820
}
3921
}
40-
max = Math.max(max, count);
4122
}
4223
}
43-
return max;
24+
return -1;
4425
}
4526

46-
private int minCellColumn(boolean[][] table, int i, int j) {
47-
// ?????????????????????????????????
48-
int max = 0;
49-
for (int l = 1; l < 50; l++) {
50-
for (int k = i; k < j + l && k < table.length; k++) {
51-
int count = 0;
52-
for (int j2 = j; k < j + l && j2 < table[0].length; j2++) {
53-
if (table[k][j2] == table[k][j]) {
54-
count++;
55-
} else {
56-
break;
57-
}
27+
private boolean checkRow(boolean[][] table, int i, int j, int r) {
28+
for (int i2 = i; i2 < i + r; i2++) {
29+
int count = 0;
30+
for (int j2 = j; j2 < j + r; j2++) {
31+
if (table[i2][j2] == table[i2][j]) {
32+
count++;
33+
} else {
34+
break;
5835
}
59-
max = Math.max(max, count);
36+
}
37+
if (count != r) {
38+
return false;
6039
}
6140
}
62-
return max;
41+
return true;
6342
}
6443

6544
// BEGIN KAWIGIEDIT TESTING
6645
// Generated by KawigiEdit-pf 2.3.0
67-
private static boolean KawigiEdit_RunTest(int testNum, String[] p0,
68-
boolean hasAnswer, int p1) {
46+
private static boolean KawigiEdit_RunTest(int testNum, String[] p0, boolean hasAnswer, int p1) {
6947
System.out.print("Test " + testNum + ": [" + "{");
7048
for (int i = 0; p0.length > i; ++i) {
7149
if (i > 0) {
@@ -83,19 +61,18 @@ private static boolean KawigiEdit_RunTest(int testNum, String[] p0,
8361
long endTime = System.currentTimeMillis();
8462
boolean res;
8563
res = true;
86-
System.out.println("Time: " + (endTime - startTime) / 1000.0
87-
+ " seconds");
88-
if (hasAnswer) {
89-
System.out.println("Desired answer:");
90-
System.out.println("\t" + p1);
91-
}
92-
System.out.println("Your answer:");
93-
System.out.println("\t" + answer);
64+
System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
9465
if (hasAnswer) {
9566
res = answer == p1;
9667
}
9768
if (!res) {
9869
System.out.println("DOESN'T MATCH!!!!");
70+
if (hasAnswer) {
71+
System.out.println("Desired answer:");
72+
System.out.println("\t" + p1);
73+
}
74+
System.out.println("Your answer:");
75+
System.out.println("\t" + answer);
9976
} else if ((endTime - startTime) / 1000.0 >= 2) {
10077
System.out.println("FAIL the timeout");
10178
res = false;
@@ -119,55 +96,48 @@ public static void main(String[] args) {
11996
int p1;
12097

12198
// ----- test 0 -----
122-
disabled = true;
99+
disabled = false;
123100
p0 = new String[] { "BB", "WW" };
124101
p1 = 4;
125-
all_right = (disabled || KawigiEdit_RunTest(0, p0, true, p1))
126-
&& all_right;
102+
all_right = (disabled || KawigiEdit_RunTest(0, p0, true, p1)) && all_right;
127103
tests_disabled = tests_disabled || disabled;
128104
// ------------------
129105

130106
// ----- test 1 -----
131-
disabled = true;
107+
disabled = false;
132108
p0 = new String[] { "W" };
133109
p1 = 1;
134-
all_right = (disabled || KawigiEdit_RunTest(1, p0, true, p1))
135-
&& all_right;
110+
all_right = (disabled || KawigiEdit_RunTest(1, p0, true, p1)) && all_right;
136111
tests_disabled = tests_disabled || disabled;
137112
// ------------------
138113

139114
// ----- test 2 -----
140-
disabled = true;
115+
disabled = false;
141116
p0 = new String[] { "WBBB", "WBBB", "WWWW" };
142117
p1 = 9;
143-
all_right = (disabled || KawigiEdit_RunTest(2, p0, true, p1))
144-
&& all_right;
118+
all_right = (disabled || KawigiEdit_RunTest(2, p0, true, p1)) && all_right;
145119
tests_disabled = tests_disabled || disabled;
146120
// ------------------
147121

148122
// ----- test 3 -----
149-
disabled = true;
123+
disabled = false;
150124
p0 = new String[] { "W", "B", "W", "W", "W" };
151125
p1 = 1;
152-
all_right = (disabled || KawigiEdit_RunTest(3, p0, true, p1))
153-
&& all_right;
126+
all_right = (disabled || KawigiEdit_RunTest(3, p0, true, p1)) && all_right;
154127
tests_disabled = tests_disabled || disabled;
155128
// ------------------
156129

157130
// ----- test 4 -----
158131
disabled = false;
159-
p0 = new String[] { "BWBBWBB", "WWBWWBW", "BBBBBBW", "WBBBBWB",
160-
"BBWWWWB", "WWWWWWW", "BBWWBBB" };
132+
p0 = new String[] { "BWBBWBB", "WWBWWBW", "BBBBBBW", "WBBBBWB", "BBWWWWB", "WWWWWWW", "BBWWBBB" };
161133
p1 = 9;
162-
all_right = (disabled || KawigiEdit_RunTest(4, p0, true, p1))
163-
&& all_right;
134+
all_right = (disabled || KawigiEdit_RunTest(4, p0, true, p1)) && all_right;
164135
tests_disabled = tests_disabled || disabled;
165136
// ------------------
166137

167138
if (all_right) {
168139
if (tests_disabled) {
169-
System.out
170-
.println("You're a stud (but some test cases were disabled)!");
140+
System.out.println("You're a stud (but some test cases were disabled)!");
171141
} else {
172142
System.out.println("You're a stud (at least on given cases)!");
173143
}

src/Chopsticks.java

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import java.util.Arrays;
2+
3+
// Paste me into the FileEdit configuration dialog
4+
5+
public class Chopsticks {
6+
public int getmax(int[] length) {
7+
int count = 0;
8+
Arrays.sort(length);
9+
10+
for (int pointer = 0; pointer < length.length-1; pointer++) {
11+
if (length[pointer] == length[pointer + 1]) {
12+
count++;
13+
pointer++;
14+
}
15+
}
16+
return count;
17+
}
18+
19+
// BEGIN CUT HERE
20+
public static void main(String[] args) {
21+
if (args.length == 0) {
22+
ChopsticksHarness.run_test(-1);
23+
} else {
24+
for (int i = 0; i < args.length; ++i)
25+
ChopsticksHarness.run_test(Integer.valueOf(args[i]));
26+
}
27+
}
28+
// END CUT HERE
29+
}
30+
31+
// BEGIN CUT HERE
32+
class ChopsticksHarness {
33+
public static void run_test(int casenum) {
34+
if (casenum != -1) {
35+
if (runTestCase(casenum) == -1)
36+
System.err.println("Illegal input! Test case " + casenum
37+
+ " does not exist.");
38+
return;
39+
}
40+
41+
int correct = 0, total = 0;
42+
for (int i = 0;; ++i) {
43+
int x = runTestCase(i);
44+
if (x == -1) {
45+
if (i >= 100)
46+
break;
47+
continue;
48+
}
49+
correct += x;
50+
++total;
51+
}
52+
53+
if (total == 0) {
54+
System.err.println("No test cases run.");
55+
} else if (correct < total) {
56+
System.err.println("Some cases FAILED (passed " + correct + " of "
57+
+ total + ").");
58+
} else {
59+
System.err.println("All " + total + " tests passed!");
60+
}
61+
}
62+
63+
static boolean compareOutput(int expected, int result) {
64+
return expected == result;
65+
}
66+
67+
static String formatResult(int res) {
68+
return String.format("%d", res);
69+
}
70+
71+
static int verifyCase(int casenum, int expected, int received) {
72+
System.err.print("Example " + casenum + "... ");
73+
if (compareOutput(expected, received)) {
74+
System.err.println("PASSED");
75+
return 1;
76+
} else {
77+
System.err.println("FAILED");
78+
System.err.println(" Expected: " + formatResult(expected));
79+
System.err.println(" Received: " + formatResult(received));
80+
return 0;
81+
}
82+
}
83+
84+
static int runTestCase(int casenum) {
85+
switch (casenum) {
86+
case 0: {
87+
int[] length = { 5, 5 };
88+
int expected__ = 1;
89+
90+
return verifyCase(casenum, expected__,
91+
new Chopsticks().getmax(length));
92+
}
93+
case 1: {
94+
int[] length = { 1, 2, 3, 2, 1, 2, 3, 2, 1 };
95+
int expected__ = 4;
96+
97+
return verifyCase(casenum, expected__,
98+
new Chopsticks().getmax(length));
99+
}
100+
case 2: {
101+
int[] length = { 1 };
102+
int expected__ = 0;
103+
104+
return verifyCase(casenum, expected__,
105+
new Chopsticks().getmax(length));
106+
}
107+
case 3: {
108+
int[] length = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
109+
int expected__ = 0;
110+
111+
return verifyCase(casenum, expected__,
112+
new Chopsticks().getmax(length));
113+
}
114+
case 4: {
115+
int[] length = { 35, 35, 35, 50, 16, 30, 10, 10, 35, 50, 16, 16,
116+
16, 30, 50, 30, 16, 35, 50, 30, 10, 50, 50, 16, 16, 10, 35,
117+
50, 50, 50, 16, 35, 35, 30, 35, 10, 50, 10, 50, 50, 16, 30,
118+
35, 10, 10, 30, 10, 10, 16, 35 };
119+
int expected__ = 24;
120+
121+
return verifyCase(casenum, expected__,
122+
new Chopsticks().getmax(length));
123+
}
124+
125+
// custom cases
126+
127+
/*
128+
* case 5: { int[] length = ; int expected__ = ;
129+
*
130+
* return verifyCase(casenum, expected__, new
131+
* Chopsticks().getmax(length)); }
132+
*/
133+
/*
134+
* case 6: { int[] length = ; int expected__ = ;
135+
*
136+
* return verifyCase(casenum, expected__, new
137+
* Chopsticks().getmax(length)); }
138+
*/
139+
/*
140+
* case 7: { int[] length = ; int expected__ = ;
141+
*
142+
* return verifyCase(casenum, expected__, new
143+
* Chopsticks().getmax(length)); }
144+
*/
145+
default:
146+
return -1;
147+
}
148+
}
149+
}
150+
151+
// END CUT HERE

0 commit comments

Comments
 (0)