Advertisement
junbjn98

phỏm

Jul 10th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.02 KB | None | 0 0
  1. int ádasdas(String s) {
  2.     if (checkPhomU(s))
  3.         return 0;
  4.  
  5.     List<String> cards = new ArrayList<String>();
  6.     String ss = "";
  7.     for (int i = 0; i < s.length(); i++) {
  8.         ss = ss + s.charAt(i);
  9.         if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
  10.             cards.add(ss);
  11.             ss = "";
  12.         }
  13.     }
  14.    
  15.     Collections.sort(cards);
  16.  
  17.     int min_1 = Math.min(ck4Cay(cards), ckSanh(cards));
  18.     if (min_1 == 1) return 1;
  19.  
  20.     int min_2 = 9;
  21.     while (true) {
  22.         int i = cards.size() - 2;
  23.         String tmp = "";
  24.         while (i >= 0 && (cards.get(i).compareTo(cards.get(i + 1)) > 0))
  25.             i--;
  26.         if (i < 0)
  27.             break;
  28.         else {
  29.             int k = cards.size() - 1;
  30.             while (cards.get(k).compareTo(cards.get(i)) < 0)
  31.                 k--;
  32.  
  33.             tmp = cards.get(k);
  34.             cards.set(k, cards.get(i));
  35.             cards.set(i, tmp);
  36.  
  37.             int h = cards.size() - 1, o = i + 1;
  38.             while (h > o) {
  39.                 tmp = cards.get(h);
  40.                 cards.set(h, cards.get(o));
  41.                 cards.set(o, tmp);
  42.                 o++;
  43.                 h--;
  44.             }
  45.         }
  46.         min_2 = Math.min(min_2, Math.min(ck4Cay(cards), ckSanh(cards)));
  47.         if (min_2 == 1) return 1;
  48.     }
  49.  
  50.     return Math.min(min_1, min_2);
  51. }
  52.  
  53.  
  54.  
  55. int ckSanh(List<String> cards) {
  56.     int c = 0;
  57.     for (int i = 0; i < 3; i++) {
  58.         String card[] = new String[3];
  59.         int num[] = new int[3];
  60.         for (int j = 0; j < 3; j++) {
  61.             card[j] = cards.get(i * 3 + j);
  62.             num[j] = Integer.parseInt(card[j].substring(0, card[j].length() - 1));
  63.         }
  64.  
  65.         int c1 = 2, c2 = 0;
  66.         if (num[0] == num[1] && num[1] == num[2])
  67.             c1 = 0;
  68.         else if (num[0] != num[1] && num[0] != num[2] && num[1] != num[2])
  69.             c1 = 2;
  70.         else
  71.             c1 = 1;
  72.  
  73.         if (num[0] > 11)
  74.             c2 = 3;
  75.         else
  76.             for (int j = 1; j < 3; j++)
  77.                 c2 += (card[0].charAt(card[0].length() - 1) != card[j].charAt(card[j].length() - 1)) ? 1
  78.                         : (num[j] - num[0] != j) ? 1 : 0;
  79.         c += Math.min(c1, c2);
  80.     }
  81.     return c;
  82. }
  83.  
  84. boolean checkPhomU(String t) {
  85.     int rLe = 0, v = 0, q = 0, y = 0, d = 0;
  86.     for (int i = 0, j = 0; i < 512; j = ++i) {
  87.         String s = t;
  88.         int[] c = new int[14];
  89.         for (char x = 64; ++x < 90;)
  90.             for (y = 15; y-- > 0;) {
  91.                 d = 2;
  92.                 if (s != (s = s.replace("" + y + x, ""))) {
  93.                     d = j % 2;
  94.                     j /= 2;
  95.                     if (d > 0)
  96.                         c[y]++;
  97.                     else
  98.                         v++;
  99.                 }
  100.                 if (d > 0) {
  101.                     if (v > 2)
  102.                         q += v;
  103.                     v = 0;
  104.                 }
  105.             }
  106.         for (int e : c)
  107.             q += e > 2 ? e : 0;
  108.  
  109.         rLe |= q /= 9;
  110.     }
  111.     return rLe == 1;
  112. }
  113.  
  114. int ck4Cay(List<String> cards) {
  115.     int c = 0;
  116.     int num[] = new int[5];
  117.     for (int i = 0; i < 5; i++) {
  118.         String cI = cards.get(i);
  119.         num[i] = Integer.parseInt(cI.substring(0, cI.length() - 1));
  120.     }
  121.  
  122.     int c1 = 0, c2 = 0;
  123.     String card_0 = cards.get(0);
  124.     int card_0_l = card_0.length();
  125.     for (int i = 1; i < 4; i++) {
  126.         c1 += num[0] == num[i] ? 0 : 1;
  127.         boolean checkNum = (num[0] + i) == num[i];
  128.         boolean checkSuit = card_0.charAt(card_0_l - 1) == cards.get(i).charAt(cards.get(i).length() - 1);
  129.         c2 += checkNum && checkSuit ? 0 : 1;
  130.     }
  131.     c += Math.min(c1, c2);
  132.  
  133.     for (int i = 5; i < 9; i++) {
  134.         if (cards.get(i).charAt(cards.get(i).length() - 1) != cards.get(4).charAt(cards.get(4).length() - 1)) {
  135.             c++;
  136.             continue;
  137.         }
  138.         String n = cards.get(i).substring(0, cards.get(i).length() - 1);
  139.         if (Integer.parseInt(n) != (num[4] + i - 4))
  140.             c++;
  141.     }
  142.     return c;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement