Cod sursa(job #2179727)

Utilizator xsorinJohn Smith xsorin Data 20 martie 2018 13:39:08
Problema Jocul Flip Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 3.23 kb
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
import java.io.*;
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
public class Main
{
    public static int make_sum(int[] v)
{
    int suma=0;
    for(int i=0;i<v.length;i++)
        suma+=v[i];
    return suma;
}

private static String input = "flip.in";
private static String output = "flip.out";
	public static void main(String[] args) {
		BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(output));
        BufferedReader bufferedReader = new BufferedReader( new FileReader(input), 2048);
		int[][] mat = new int[16][16];
		int row;
		int col;
		int s;
		int suma=0;
		int[] rows=new int[16];
		int[] cols=new int[16];
		int[] temp=new int[16];
		while(bufferedReader.readLine()!=NULL) {
            String line = bufferedReader.readLine();
            String[] parts = line.split(" ");
                row = Integer.parseInt(parts[0]);
                col = Integer.parseInt(parts[1]);
                for (int i=0;i<row;i++)
                    for(int j=0;j<col;j++)
                        mat[i][j]=Integer.parseInt(bufferedReader.readLine());
                for(int i=0;i<row;i++)
                  {  for(int j=0;j<col;j++)
                            {rows[j]=mat[i][j];
                            temp[j]=mat[i][j]*-1;}
                            
                            
                            if (make_sum(rows)<make_sum(temp))
                        
                            {
                                for(int p=0;p<col;p++)
                                mat[i][p]=temp[p];
                            }
                        else
                            {
                                for(int p=0;p<col;p++)
                                mat[i][p]=rows[p];
                            }
                  }
                for(int i=0;i<col;i++)
                  {  for(int j=0;j<row;j++)
                            {cols[j]=mat[j][i];
                            temp[j]=mat[j][i]*-1;}
                            
                            
                            if (make_sum(cols)<make_sum(temp))
                        
                            {
                                for(int p=0;p<row;p++)
                                mat[p][i]=temp[p];
                            }
                        else
                            {
                                for(int p=0;p<row;p++)
                                mat[p][i]=cols[p];
                            }
                            
                  }  
                        
                        
               for(int i=0;i<row;i++)
                    for(int j=0;j<col;j++)
    bufferedWriter.write(suma);
        bufferedReader.close();
        bufferedWriter.close();
}
}	
}