import java.io.*; class Asst3 { // This class simulates a simple data monitoring device. // Input 'readings' are lines of the form * NNN MMM, where // NNN and MMM are considered as readings in the range 000 through 999. // The output, for each input, is the -max- and -min- of the last RANGE // NNN values, and the -max- and -min- of the last RANGE MMM values. static final short QSIZE = 32; // must be power of 2 for easy % (mod) static final short RANGE = 25; // must be <= QSIZE // These arrays are the data for NNN values and MMM values. static short [] Ns = new short [QSIZE]; static short [] Ms = new short [QSIZE]; // These variables record how many data items are stored and // which is the first one. static short numData = 0; static short queueHead = 0; // This method reads the next line of data, and returns true // if there was one, false if not. It also echos input. static boolean readLine () throws IOException { short queueFree; // Check if there's any more data. if (Io. charInput () != '*') return false; Io. charOutput ('*'); // Read data into the queue. queueFree = (short) ((queueHead + numData) % QSIZE); Ns [queueFree] = Io. decimalInput (); Ms [queueFree] = Io.decimalInput (); Io. charOutput (' '); Io. decimalOutput (Ns [queueFree]); Io. charOutput (' '); Io. decimalOutput (Ms [queueFree]); Io. charOutput ('\n'); // If there are already 25 data, remove the head of the queue if (numData >= RANGE) queueHead = (short) ((queueHead + 1) % QSIZE); // Otherwise increase the size else ++ numData; return true; } public static void main (String [] args) throws IOException { while (readLine ()) { Io. decimalOutput (maxArray (Ns)); Io. charOutput (' '); Io. decimalOutput (minArray (Ns)); Io. charOutput (' '); Io. decimalOutput (maxArray (Ms)); Io. charOutput (' '); Io. decimalOutput (minArray (Ms)); Io. charOutput ('\n'); } } static short minArray (short [] x) { short i; short minVal = +32767; short index; for (i = 0; i < numData; ++i) { index = (short) ((queueHead + i) % QSIZE); if (minVal > x [index]) minVal = x [index]; } return minVal; } static short maxArray (short [] x) { short i; short maxVal = -32768; short index; for (i = 0; i < numData; ++i) { index = (short) ((queueHead + i) % QSIZE); if (maxVal < x [index]) maxVal = x [index]; } return maxVal; } }