ตรวจรางวัลลอตเตอรี
โจทย์
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
| Input | Output |
|---|---|
| 199606 | 6000000 |
| 173606 | 4000 |
| 199388 | 4000 |
| 199389 | 0 |
โค้ด
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);
}
}คำอธิบาย
ปรับปรุงล่าสุด