Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) throws IOException {
- int num = 12345;
- String res = "";
- StringBuilder response = new StringBuilder();
- while (true){
- try {
- String a = String.format("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%d", num);
- URL url = new URL(a);
- URLConnection conn = url.openConnection();
- BufferedReader br = new BufferedReader(
- new InputStreamReader(conn.getInputStream()));
- while ((res = br.readLine()) != null){
- response.append(res);
- }
- res = response.toString();
- response.setLength(0);
- if (res.contains("Divide")){
- num /= 2;
- }
- else {
- Pattern p = Pattern.compile("\\d+$");
- Matcher m = p.matcher(res);
- if (m.find()) num = Integer.parseInt(m.group(0));
- else {
- System.out.println(res);
- break;
- }
- }
- System.out.println(num);
- }
- catch (NumberFormatException e){
- System.out.println(res);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment