Skip to Content
CoursesCSC122โปรแกรมจำลองหวยใต้ดิน

โปรแกรมจำลองหวยใต้ดิน

โจทย์

The underground lottery is a type of lottery organized informally within communities. Players write down the 2-3 digit numbers they wish to bet on. The players can select amount of money for their bet and the patterns of bet. If they win the prizes, their bet will be multiplied by the prize rate. The patterns of bet and the prize are listed as follows:

  • Straight (เต็ง, ตรง) – A bet where the numbers must match exactly in the correct order as listed below:
    • 3 Upper Digits (3 ตัวบน) – The last 3 digits of the first prize number. Prize rate is 450 baht.
    • 2 Upper Digits (2 ตัวบน) – The last 2 digits of the first prize number. Prize rate is 65 baht.
    • 3 Lower Digits (3 ตัวล่าง) – A 3-digit prize number, typically drawn in 4 sets of 3-front digits prize and 3-back digits prize. Prize rate is 90 baht.
    • 2 Lower Digits (2 ตัวล่าง) – A 2-digit prize number, typically drawn in 1 set of 2-digit prize. Prize rate is 65 baht.
  • Upper Run (วิ่งบน) – A bet where a selected number (only one number) matches any of the 3 upper digits. Prize rate is 90 baht.
  • Lower Run (วิ่งล่าง) – A bet where a selected number (only one number) matches either of the 2 lower digits. Prize rate is 65 baht.
  • Boxed (โต๊ด) – A bet where the 3 digit-numbers must match with 3 upper digits but can be in any order (including original order). Prize rate is 90 baht.
  • For example, Thai lottery ticket has 6 digits as shown in the figure.

For this round

  • The first prize is 558700
  • The 3-digits front is 285 or 418
  • The 3-digits back is 685 or 824
  • The 2-digits is 51

Input:

  • There are 2 list of numbers.
    • The first list are 7 numbers that we select for the bet patterns in the following order: Straight 3 Upper Digits, Straight 2 Upper Digits, Straight 3 Lower Digits, Straight 2 Lower Digits, Upper Run, Lower Run, and Boxed.
    • The second list are amount of bet (Baht) for each bet patterns.

Output:

  • An amount of prize if there is no prize win, print 0.
InputOutput
700 00 418 51 7 5 070
1 1 1 1 1 1 1
915

โค้ด

import java.util.*; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] patterns = new String[7]; int[] bets = new int[7]; for (int i = 0; i < 7; i++) { patterns[i] = scanner.next(); } for (int i = 0; i < 7; i++) { bets[i] = scanner.nextInt(); } int prize = 0; String[] firstPrize = {"558700", "700", "00"}; String[] threeDigitPrize = {"285", "418", "685", "824"}; String twoDigitPrize = "51"; // Straight 3 Upper Digits if (patterns[0].endsWith(firstPrize[1])) { prize += bets[0] * 450; } // Straight 2 Upper Digits if (patterns[1].endsWith(firstPrize[2])) { prize += bets[1] * 65; } // Straight 3 Lower Digits if (Arrays.asList(threeDigitPrize).contains(patterns[2])) { prize += bets[2] * 90; } // Straight 2 Lower Digits if (patterns[3].endsWith(twoDigitPrize)) { prize += bets[3] * 65; } // Upper Run Pattern for (char ch: firstPrize[1].toCharArray()) { if (patterns[4].equals(ch + "")) { prize += bets[4] * 90; break; } } // Lower Run Pattern for (char ch: twoDigitPrize.toCharArray()) { if (patterns[5].equals(ch + "")) { prize += bets[5] * 65; break; } } // Boxed Pattern int matches = 0; for (char ch: patterns[6].toCharArray()) { for (char chPrize : firstPrize[1].toCharArray()) { if (chPrize == ch) { matches++; break; } } } if (matches == 3) { prize += bets[6] * 90; } System.out.println(prize); } }

คำอธิบาย

ปรับปรุงล่าสุด