Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hash_code_test;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOError;
- import java.io.IOException;
- /**
- *
- * @author MiguelFreitas(114127
- */
- public class Main {
- public static char[][] pizza;
- public static String example_file;
- public static BufferedReader br = null;
- public static FileReader fr = null;
- public static int cols = 0;
- public static int rows = 0;
- //minimo de cada um dos ingredientes
- public static int min_each_ing_slice = 0;
- //maximo de cells por fatia
- public static int max_cells_slice = 0;
- public static void main(String[] args) {
- pizza = null;
- example_file = "example.in";
- String current_file_line = "";
- try {
- fr = new FileReader(example_file);
- br = new BufferedReader(fr);
- current_file_line = br.readLine();
- String[] size_data = current_file_line.split(" ");
- rows = Integer.parseInt(size_data[0]);
- cols = Integer.parseInt(size_data[1]);
- min_each_ing_slice = Integer.parseInt(size_data[2]);
- max_cells_slice = Integer.parseInt(size_data[3]);
- pizza = new char[rows][cols];
- int current_column = 0;
- while ((current_file_line = br.readLine()) != null) {
- for (int i = 0; i < cols; i++) {
- pizza[current_column][i] = current_file_line.charAt(i);
- }
- current_column++;
- }
- printMatrix();
- System.out.println("\n\nTestando fatia teste: 0,0,2,1");
- System.out.println(evaluate_slice(new Slice(0,0,2,1)));
- } catch (IOException e) {
- System.out.println("File not found");
- }
- }
- public static void printMatrix() {
- for (int i = 0; i < pizza.length; i++) {
- for (int j = 0; j < pizza[0].length; j++) {
- System.out.print(pizza[i][j] + " ");
- }
- System.out.println("");
- }
- }
- public static boolean evaluate_slice(Slice slice) {
- int num_m = 0;
- int num_t = 0;
- if (slice.get_num_cells() > max_cells_slice) {
- return false;
- }
- for (int i = slice.row_a; i < slice.row_b; i++) {
- for (int j = slice.col_a; j < slice.col_b; j++) {
- if (pizza[i][j] == 'M') {
- num_m++;
- } else {
- if (pizza[i][j] == 'T') {
- num_t++;
- }
- }
- }
- }
- System.out.println("num_m: "+num_m);
- System.out.println("num_t: "+num_t);
- return num_m > min_each_ing_slice && num_t > min_each_ing_slice;
- }
- public static class Slice {
- public int row_a;
- public int row_b;
- public int col_a;
- public int col_b;
- public Slice() {
- }
- public Slice(int row_a, int row_b, int col_a, int col_b) {
- this.row_a = row_a;
- this.row_b = row_b;
- this.col_a = col_a;
- this.col_b = col_b;
- }
- public int get_num_cells(){
- return Math.abs(row_b-row_a) * Math.abs(col_b - col_a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement