Lab5-Lottery


5530288221  นายนภนต์ ธนุภาพรังสรรค์ (COM21900) (12/12/2012 (4:27:48 PM))

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"));
    
                  
    String[] data = new String[1000];
    int[] numInt = new int[1000];
    int f = 0;
       
    while (in.hasNext()) {
      for (int l = 1; l <= 6; l++) in.next();
      data[f] = in.next();
      numInt[f] = Integer.parseInt(data[f]);
      f++;
      }
    
    int[] c = new int[100];
    
    for (int m = 0; m <= f - 1; m++) {
      for (int n = 0; n < 100; n++ ) {
        if (numInt[m] == n) c[n]++;
        }
      }

   
    System.out.print("เลขท้ายสองตัวที่ไม่เคยออกเลยคือ:");
    // แสดงรายการของเลขที่ไม่เคยออก (แสดงต่อ ๆ กันไปบนบรรทัดเดียวกัน แต่ละตัวคั่นด้วยช่องว่าง เช่น 12 41 32)
    // ถ้าไม่มีเลขที่ไม่เคยออก ก็ไม่ต้องแสดงอะไร
    for (int x = 0; x < 100; x++) {
      if (c[x] == 0) {
        if (x < 10) System.out.print(" " + "0" + x);
        else System.out.print(" " + x);
        }
      } 

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

 
    System.out.println();
  }
}
SM=0, CM=34, ST=58, KY=1347, 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 ;