Lab5-Lottery


5530202221  นายเทอดพงศ์ เวณุนันทน์ (COM22023) (12/17/2012 (11:37:02 AM))

MiniQuiz + TestScript
JLab>javac Lottery.java
JLab>
JLab>java Selftest 

JLab> testLottery : ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok  (10.0/10.0)
JLab> : -----------------------------
JLab> : ?????? 10.0 ????? (???? 10.0)
JLab> : -----------------------------
JLab> :<POINT>10.0</POINT> (<TOTAL>10.0</TOTAL> )
JLab>

ได้ 10 คะแนน
Source Code
import java.util.Scanner;
import java.io.*;

public class Lottery {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new File("lottery.txt"));
    int count[] = new int[100];
    while (in.hasNext()) {
    in.next(); in.next(); in.next(); in.next(); in.next(); in.next();
    int n = in.nextInt();
    count[n]++;
    }
    in.close();
    int max = 0;
    for (int a = 0; a < 100; a++) {
       if (max <= count[a]) {
         max = count[a];
       }
    }
    System.out.print("เลขท้ายสองตัวที่ไม่เคยออกเลยคือ:");
    // แสดงรายการของเลขที่ไม่เคยออก (แสดงต่อ ๆ กันไปบนบรรทัดเดียวกัน แต่ละตัวคั่นด้วยช่องว่าง เช่น 12 41 32)
    // ถ้าไม่มีเลขที่ไม่เคยออก ก็ไม่ต้องแสดงอะไร
    for (int b = 0; b < 100; b++) {
     if (count[b] == 0 && b < 10) {
        System.out.print("0" + b + " "); }
     if (count[b] == 0 && b >= 10) {
        System.out.print(b + " "); }
}
    System.out.println();
    System.out.print("เลขท้ายสองตัวที่ออกบ่อยสุดคือ:");
    // แสดงรายการของเลขที่ออกบ่อยสุด (แสดงต่อ ๆ กันไปบนบรรทัดเดียวกัน แต่ละตัวคั่นด้วยช่องว่าง เช่น 69 18)
    // เลขที่ออกบ่อยสุด อาจมีมากกว่าหนึ่งตัว
    for (int b = 0; b < 100; b++) {
     if (count[b] == max && b < 10) {
        System.out.print("0" + b + " "); }
     if (count[b] == max && b >= 10) {
        System.out.print(b + " "); }
}




    System.out.println();
  }
}
SM=4, CM=33, ST=44, KY=1146, TR=60:00
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;