Lab5-Lottery


5530244621  นายธนาวัฒน์ สิทธิสันติกุล (COM21900) (12/18/2012 (11:56:11 AM))

MiniQuiz + TestScript
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"));
    Scanner kb = new Scanner(System.in);
    int []t = new int [100];
    while (in.hasNext()) {
      String g = in.nextLine().trim();
      int h = Integer.parseInt(g.substring(g.lastIndexOf(" ")+1));
      t[h]++;
    }
    in.close();
   // for (int i = 0; i < t.length; i++) {
     // System.out.println(t[i]);
    //}
    String no = " ";
    for (int i = 0; i < t.length; i++) {
      if (t[i] == 0) {
        if (i < 10) {
          no += "0" + i + " ";
        } else {
          no = no + i + " ";
        }
      }
    }
    
    System.out.print("เลขท้ายสองตัวที่ไม่เคยออกเลยคือ:");
    // แสดงรายการของเลขที่ไม่เคยออก (แสดงต่อ ๆ กันไปบนบรรทัดเดียวกัน แต่ละตัวคั่นด้วยช่องว่าง เช่น 12 41 32)
    // ถ้าไม่มีเลขที่ไม่เคยออก ก็ไม่ต้องแสดงอะไร

    
    
    System.out.print(no);
    String max = " ";
    int maxv = t[0];
    for (int i = 1; i < t.length; i++) {
      if (t[maxv] < t[i]) maxv = i;
    }
    int count = 0;
    for (int i = 0; i < t.length; i++) {
      if (t[i] == t[maxv]) count++;
    }
    int maxvl[] = new int[count];
    count = 0;
    for (int i = 0; i < t.length; i++) {
      if (t[i] == t[maxv]) {
        maxvl[count] = i;
        count++;
      }
    }
    for (int i = 0; i < maxvl.length; i++) {
      if (maxvl[i] < 10) {
        max += "0" + maxvl[i] + " ";
      } else {
        max += maxvl[i] + " ";
      }
    }
    System.out.println();
    System.out.print("เลขท้ายสองตัวที่ออกบ่อยสุดคือ:");
    // แสดงรายการของเลขที่ออกบ่อยสุด (แสดงต่อ ๆ กันไปบนบรรทัดเดียวกัน แต่ละตัวคั่นด้วยช่องว่าง เช่น 69 18)
    // เลขที่ออกบ่อยสุด อาจมีมากกว่าหนึ่งตัว


      
      
      
      
    
    System.out.print(max);


    System.out.println();
  }
}
SM=1, CM=90, ST=69, KY=6412, 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 ;