Created
June 21, 2016 12:49
-
-
Save josinSbazin/33deef84930a72d5ab884dfb3e2d69f5 to your computer and use it in GitHub Desktop.
level15.lesson12.home09
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
package com.javarush.test.level15.lesson12.home09; | |
/* Парсер реквестов | |
Считать с консоли URl ссылку. | |
Вывести на экран через пробел список всех параметров (Параметры идут после ? и разделяются &, например, lvl=15). | |
URL содержит минимум 1 параметр. | |
Если присутствует параметр obj, то передать его значение в нужный метод alert. | |
alert(double value) - для чисел (дробные числа разделяются точкой) | |
alert(String value) - для строк | |
Пример 1 | |
Ввод: | |
http://javarush.ru/alpha/index.html?lvl=15&view&name=Amigo | |
Вывод: | |
lvl view name | |
Пример 2 | |
Ввод: | |
http://javarush.ru/alpha/index.html?obj=3.14&name=Amigo | |
Вывод: | |
obj name | |
double 3.14 | |
*/ | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
public class Solution { | |
public static void main(String[] args) { | |
ArrayList<String> list = new ArrayList<String>(); | |
String url; | |
String words[]; | |
StringBuilder toPrint = new StringBuilder(""); | |
try { | |
url = (new BufferedReader(new InputStreamReader(System.in))).readLine(); | |
words = (url.substring(url.indexOf('?')+1)).split("(&+)"); | |
for (String tmp : words) { | |
if (!tmp.equals("/s") && tmp.contains("=")) { | |
toPrint.append(tmp.substring(0, tmp.indexOf("="))+" "); | |
if (tmp.substring(0, tmp.indexOf("=")).trim().replaceAll("\\s{2,}", "").equals("obj")) list.add(tmp.substring(tmp.indexOf("=")+1).trim()); | |
} | |
else toPrint.append(tmp+" "); | |
} | |
System.out.println(toPrint.toString().replaceAll("\\s+"," ").trim()); | |
for (String tmp : list) { | |
if (tmp.matches("^[\\+\\-]?[0-9]+[\\.]?[0-9]+$")) alert(Double.parseDouble(tmp)); | |
else alert(tmp); | |
} | |
} catch ( Exception e) {}//add your code here | |
} | |
public static void alert(double value) { | |
System.out.println("double " + value); | |
} | |
public static void alert(String value) { | |
System.out.println("String " + value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment