Created
June 30, 2016 12:38
-
-
Save omengye/eb67eea5989faab33f041315a66fa5f4 to your computer and use it in GitHub Desktop.
JAVA Solution for t/289369 in V2EX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JAVA Solution for t/289369 | |
*/ | |
package test; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class TestJava { | |
public class ResObj { | |
private int value; | |
private int winner; | |
private boolean playerPair; | |
private boolean bankerPair; | |
public ResObj(int value, int winner, boolean playerPair, boolean bankerPair) { | |
this.value = value; | |
this.winner = winner; | |
this.playerPair = playerPair; | |
this.bankerPair = bankerPair; | |
} | |
public int getValue() { | |
return value; | |
} | |
public int getWinner() { | |
return winner; | |
} | |
public boolean isPlayerPair() { | |
return playerPair; | |
} | |
public boolean isBankerPair() { | |
return bankerPair; | |
} | |
} | |
public class RawObj { | |
private String a; | |
private int b; | |
private int c; | |
private int d; | |
private int f; | |
private boolean g; | |
private boolean h; | |
public RawObj(String a, int b) { | |
this.a = a; | |
this.b = b; | |
this.c = e(a.substring(b, b+1)); | |
this.d = 15 & e(a.substring(b+1, b+2)); | |
this.f = (12 & c) >> 2; | |
this.g = (2 & c) > 0; | |
this.h = (1 & c) > 0; | |
} | |
public String getA() { | |
return a; | |
} | |
public int getB() { | |
return b; | |
} | |
public int getC() { | |
return c; | |
} | |
public int getD() { | |
return d; | |
} | |
public int getF() { | |
return f; | |
} | |
public boolean isG() { | |
return g; | |
} | |
public boolean isH() { | |
return h; | |
} | |
public ResObj toResObj() { | |
return new ResObj(d, f, g, h); | |
} | |
} | |
public static int e(String a) { | |
Pattern pattern = Pattern.compile("^[0-9]+"); | |
Matcher matcher = pattern.matcher(a); | |
while (matcher.find()) { | |
return Integer.parseInt(matcher.group(0)); | |
} | |
char startChar = a.charAt(0); | |
return (int)startChar - 97 + 10; | |
} | |
public List<ResObj> queryTestObjList(String a) { | |
List<ResObj> objList = new ArrayList<>(); | |
int d = 3; | |
for (int g=0; g<a.length()-1; g+=2) { | |
RawObj rawObj = new RawObj(a, g); | |
ResObj resObj = rawObj.toResObj(); | |
if (resObj.winner != d) { | |
objList.add(resObj); | |
} | |
else { | |
objList.clear(); | |
} | |
} | |
return objList; | |
} | |
public static boolean isEmpty(String str) { | |
if (str == null || str.equals("")) { | |
return true; | |
} | |
return false; | |
} | |
public List<ResObj> test(String a, String b) { | |
List<ResObj> resList = new ArrayList<>(); | |
if (isEmpty(a) || isEmpty(b)) { | |
return resList; | |
} | |
else if (a.equals("7bal") || a.equals("bal")) { | |
return queryTestObjList(b); | |
} | |
else if (a.equals("rol") || a.equals("rofl")) { | |
String[] bSps = b.split(";"); | |
for (String bSp : bSps) { | |
resList.addAll(queryTestObjList(bSp)); | |
} | |
} | |
else { | |
// TODO - | |
} | |
return resList; | |
} | |
public static void main(String[] args) { | |
TestJava testJava = new TestJava(); | |
String a = "60o0749460o07134482"; | |
List<ResObj> ts = testJava.test("bal", a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment