Question

1093-04 American Computer Sclence Lesg Intermediate DivisionーPRoa RAMMING Contest wa oni Back in the Saddle Agnin Problem A matrix is a 2 columns, and its called 3-by-2 matric A saddle point of a matrix is any value of the marix that in buth the largst vu in its d the largest value in its column·Thr are l-ndle polde the man hms kk in the last row of the matrix had been a 6, the matrix would have only one saddle polsd & the 4 in the last row had been an 8, the matrix would have ne saddlle pointa. Finally, M the ast row har been a s, the matrix would have the single saddle point. S. (Thin i-tricky!) Input: Five above. All matrices will be Output: Print the saddle must be listed in order to receive credit. If a saddle point appears more than once (as would happen t matricen. Fach matrix starta with the number of rows (r) and cakumne () of the by the r-by-e columns. The firet data line below correponds to the sample matri amaller than 6-by-6, and all values will be positive Integrs points of ench matrix. If the matrix has no saddle pointa, print a mege to that effect. If the matrix has more than one saddle point, they may be Visted in any order, a If the 8 were changed to a 5 in the example above), it must be listed only once Sample Input: Line #1: 3, 2, s, 2, 3, i. 4, 8 Line 2: 3, 3. 3, 2, 4, 1, 1, 6, 4, 2, 5 Line #3: 4, 2, 9, 3·5·8. 6, 32 1 Line#4: 4, 3, 1, 2, 3, 4, 2,4,6,8. 1, s. 5, 7 Line #5: 3, 2, 5, 2, 6, 8, 3-8 Sample Output: Output 1: 5 and 8 Output #2: 6 Output 3: 8 and 9 Output #4: 7 and 8 Output 5: none Please wsite the prora in Java us JOPhon Pane
0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class SaddlePoint {


    private static String getSaddlePoint(int[][] array) {
        String output="";
        for (int cols = 0; cols < array[0].length; cols++) {
            int rowHigh = -1;
            int indexHigh = -1;
            for (int row = 0; row < array.length; row++) {
                if (array[row][cols] > rowHigh) {
                    rowHigh = array[row][cols];
                    indexHigh = row;
                }
            }

            boolean isColumnHighest = true;
            for (int k = 0; k < array[0].length; k++) {
                if (array[indexHigh][k] > rowHigh) {
                    isColumnHighest = false;
                }
            }
            if (isColumnHighest) {
                output+=rowHigh+", ";
            }
        }
        return output;
    }



    public static void main(String[] strings) {

        //3,2,5,2,3,1,4,8
        //3,3,3,2,4,1,1,6,4,2,5
        //4,2,9,3,5,8,6,3,2,1
        //4,3,1,2,3,4,2,4,6,8,1,3,5,7

        String sentence = JOptionPane.showInputDialog("Enter input");

        String[] splitStrings = sentence.split(",");
        int[][] matrixArr = new int[Integer.parseInt(splitStrings[0])][Integer.parseInt(splitStrings[1])];
        int counter = 2;
        for (int i = 0; i < matrixArr.length; i++) {
            for (int j = 0; j < matrixArr[0].length; j++) {
                matrixArr[i][j] = Integer.parseInt(splitStrings[counter++]);
            }
        }

        //System.out.println(Arrays.deepToString(matrixArr));

        JOptionPane.showMessageDialog(null, getSaddlePoint(matrixArr));

    }


}

////////////////Output////////

Test [-/IdeaProjects/Test] - .../src/SaddlePoint.java [Test] IntelliJ IDEA En 9:29 AM File Edit View Navigate Code Analyze ReMessage 令 (ⓢ4x 9:29 AM * File Edit View Navigate Code Analyze Refactor Build Run Iools VCs Window Help Test src) SaddlePoint

Add a comment
Know the answer?
Add Answer to:
1093-04 American Computer Sclence Lesg Intermediate DivisionーPRoa RAMMING Contest wa oni Back in the Saddle Agnin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ must use header files and implementation files as separate files. I’ll need a header file,...

    C++ must use header files and implementation files as separate files. I’ll need a header file, implementation file and the main program file at a minimum. Compress these files into one compressed file. Make sure you have adequate documentation. We like to manipulate some matrix operations. Design and implement a class named matrixMagic that can store a matrix of any size. 1. Overload the addition, subtraction, and multiplication operations. 2. Overload the extraction (>>) and insertion (<<) operators to read...

  • explanation too Problems 7-11: The augmented matrix is given for a system of equations. If the...

    explanation too Problems 7-11: The augmented matrix is given for a system of equations. If the system is consistent, find the general solution. Otherwise state that there is no solution. State the solution in vector parametric form. In your augmented matrix, draw a vertical line that represents the equal sign, label all columns of the augmented matrix, and before each new row, write the operations that give you that new row and show the scratch work on the same page...

  • Use basic java for this after importing PrintWriter object You will make a simple Magic Square...

    Use basic java for this after importing PrintWriter object You will make a simple Magic Square program for this Java Programming Assignment. Carefully read all the instructions before beginning to code. It is also required to turn in your pseudocode or a flowchart along with this program. Here are the instructions: At the beginning of the program, briefly describe to the user what a Magic Square Matrix is (described further on), and then allow them to enter “start” to begin...

  • Which set of row operations would have been used to change the Augmented Matrix to Reduced...

    Which set of row operations would have been used to change the Augmented Matrix to Reduced Row Echelon Form. 1 3 0 -21 51 ſi 0 0 -3 2 -6 25 --> 0 1 0 5 4 31 8 0 0 4 0

  • Which set of row operations would have been used to change the Augmented Matrix to Reduced...

    Which set of row operations would have been used to change the Augmented Matrix to Reduced Row Echelon Form. 1 3 0 -21 51 ſi 0 0 -3 2 -6 25 --> 0 1 0 5 4 31 8 0 0 4 0

  • I need answer to 8 4. (1 point) If Aū= 4 3 2 and Av= -3...

    I need answer to 8 4. (1 point) If Aū= 4 3 2 and Av= -3 -2 then A(3ū+ 2v) = Answer(s) submitted: (incorrect) 8. (3 points) (a) Perform the indicated row operations on the matrix A successively in the order they are given until a matrix Generated by WebWork hwehwork maa ore Mathematical Association of America Previous Problem Problem List Next Problem (3 points) (a) Perform the indicated row operations on the matrix A successively in the order they...

  • Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp...

    Write a program mexp that multiplies a square matrix by itself a specified number of times、mexp takes a single argument, which is the path to a file containing a square (k × k) matrix M and a non-negative exponent n. It computes M and prints the result Note that the size of the matrix is not known statically. You ust use malloc to allocate space for the matrix once you obtain its size from the input file. Tocompute M". it...

  • how did we get the left null space please use simple way 6% 0-0, 1:44 AM Fri May 17 , Calc 4 4 Exaimi 3 solutions Math 250B Spring 2019 1. Let A 2 6 5 (a) Find bases for and the dimensions of the four...

    how did we get the left null space please use simple way 6% 0-0, 1:44 AM Fri May 17 , Calc 4 4 Exaimi 3 solutions Math 250B Spring 2019 1. Let A 2 6 5 (a) Find bases for and the dimensions of the four fundamental subspaces. Solution Subtract row onc from row 2, then 8 times row 2 from row 3, then 5 timcs rovw 2 fro row. Finally, divide row1 by 2 to get the row reduced...

  • Thank you Please show all work Thanks 76.) [ 10 pts ] Consider the two S-boxes...

    Thank you Please show all work Thanks 76.) [ 10 pts ] Consider the two S-boxes S1 and S2 of DES shown. Three hex digits (12 bits) are provided to these two S boxes. The higher order six bits are fed to S1 and the lower order six bits are fed to S2. For the six bits input to S1, the first and last bits are used to select the row, and the middle four bits are used to select...

  • Problem: Matrix Implementation Create a class Matrix with the following method stubs for the following methods...

    Problem: Matrix Implementation Create a class Matrix with the following method stubs for the following methods described: 1. read: reads in a matrix from the command line 2. display: prints the matrix to the command line 3. getRows: returns the number of rows 4. getCols: returns the number of columns 5. set: sets the double value at a particular column/row position 6. get: returns the value stored at a particular column/row position 7. Plus: returns a new Matrix object that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT