Skip to Content
CoursesCSC122ตรวจรางวัลลอตเตอรี

ตรวจรางวัลลอตเตอรี

โจทย์

Prizes are awarded based on exact matching of numbers, with varying tiers for different matches.

  • There are some famous prizes such as 1st prize that match all digits on the ticket worth 6 million baht
  • 3-digit match at the front and the back worth 4000 baht
  • 2-digit match at the back worth 2000 baht

สำหรับงวดนี้

  • The first prize is 199606
  • The 3-digits front is 173 or 220
  • The 3-digits back is 388 or 094
  • The 2-digits is 94
InputOutput
1996066000000
1736064000
1993884000
1993890

โค้ด

import java.util.*; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String lotteryNumber = scanner.nextLine(); int prize = 0; if (lotteryNumber.equals("199606")) prize += 6000000; if (lotteryNumber.startsWith("173")) prize += 4000; if (lotteryNumber.startsWith("220")) prize += 4000; if (lotteryNumber.endsWith("388")) prize += 4000; if (lotteryNumber.endsWith("094")) prize += 4000; if (lotteryNumber.endsWith("94")) prize += 2000; System.out.println(prize); } }

คำอธิบาย

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