Advertisement
svetlozar_kirkov

Softuni Numerals [Exam 28.02.2016]

Feb 28th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package com.sve;
  2.  
  3.         import java.math.BigInteger;
  4.         import java.util.ArrayList;
  5.         import java.util.HashMap;
  6.         import java.util.Map;
  7.         import java.util.Scanner;
  8.         import java.util.regex.Matcher;
  9.         import java.util.regex.Pattern;
  10.  
  11. public class Main {
  12.  
  13.     public static void main(String[] args) {
  14.         Map<String, String> values = new HashMap<>();
  15.         values.put("aa", "0");
  16.         values.put("aba", "1");
  17.         values.put("bcc", "2");
  18.         values.put("cc", "3");
  19.         values.put("cdc", "4");
  20.         String regexString = "((aa)|(aba)|(bcc)|(cc)|(cdc))";
  21.         Pattern regexPattern = Pattern.compile(regexString);
  22.         Scanner scan = new Scanner(System.in);
  23.         String inputLine = scan.nextLine();
  24.         Matcher matcher = regexPattern.matcher(inputLine);
  25.         StringBuilder result = new StringBuilder();
  26.         while (matcher.find()) {
  27.             result.append(values.get(matcher.group(1)));
  28.         }
  29.         BigInteger resultInteger = new BigInteger(result.toString(), 5);
  30.         System.out.println(resultInteger);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement