Input
The input consists of several test cases. In each line of input, there are two integers 1 ≤ M ≤ 300, the
number of rows in the chocolate and 1 ≤ N ≤ 300, the number of columns in the chocolate. The input
should be processed until end of file is encountered.
Output
For each line of input, your program should produce one line of output containing an integer indicating
the minimum number of cuts needed to split the entire chocolate into unit size pieces.
public class Main { public static void main(String[] args) throws FileNotFoundException { File myFile = new File("file.txt"); Scanner sc = new Scanner(myFile); while(sc.hasNext()){ int M = sc.nextInt(); int N = sc.nextInt(); System.out.println(M + N - 2); } } }
Comments
Leave a comment