SHARE
TWEET

Untitled

a guest Apr 17th, 2018 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Fund;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class winTiket {
  8.     public static void main(String[] args) {
  9.         Scanner s = new Scanner(System.in);
  10.  
  11.         String input = s.nextLine();
  12.  
  13.         String[] ticket = input.split("[, ]+");
  14.  
  15.         for (int i = 0; i < ticket.length; i++) {
  16.  
  17.             if (ticket[i].length() == 20) {
  18.                 String tickets = ticket[i];
  19.                 String left = tickets.substring(0,10);
  20.                 String right = tickets.substring(10,20);
  21.                 String leftMach ="a";
  22.                 String righttMach="s";
  23.  
  24.                // String patern = ;
  25.                 Pattern patern = Pattern.compile("[\\\\@]{6,}|[\\\\$]{6,}|[\\\\#]{6,}|[\\\\^]{6,}");
  26.                 Matcher lm = patern.matcher(left);
  27.                 Matcher rm = patern.matcher(right);
  28.                 if (lm.find()){
  29.                  leftMach = lm.group();
  30.                 }
  31.                 if (rm.find()){
  32.                      righttMach = rm.group();
  33.                 }
  34.  
  35.                 if (leftMach.substring(0,1).equals(righttMach.substring(0,1))){
  36.                     int matchCount = Math.min(leftMach.length(),righttMach.length());
  37.  
  38.                         if (matchCount == 10){
  39.                             System.out.printf("ticket \"%s\" - %d%s Jackpot!%n",tickets,matchCount,leftMach.substring(0,1));
  40.                         }else {
  41.                             System.out.printf("ticket \"%s\" - %d%s%n",tickets,matchCount,leftMach.substring(0,1));
  42.  
  43.                         }
  44.                 }else {
  45.                     System.out.printf("ticket \"%s\" - no match%n",tickets);
  46.                 }
  47.  
  48.             }else {
  49.                 System.out.println("invalid ticket");
  50.             }
  51.         }
  52.  
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top